fixing popup message more than time on userform

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
i have this code but i no know where is the problem this message when popup it shows more one time please any idea to get rid of this problem
VBA Code:
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  Dim f As Range
  If TextBox2.Value = "" Then
    MsgBox "Enter Brand"
    TextBox2.SetFocus
    Exit Sub
  End If
  If TextBox3.Value = "" Then Exit Sub
  If TextBox3.Value <= 0 Or Not IsNumeric(TextBox3.Value) Then
    Cancel = True
    MsgBox "Enter a valid value"
    Exit Sub
  End If
  Set f = Sheets("sheet1").Range("B:B").Find(TextBox2, , xlValues, xlWhole)
  If Not f Is Nothing Then
    If f.Offset(, 1) < Val(TextBox3) Then
      MsgBox "Available is : " & f.Offset(, 1)
      Cancel = True
    Else
      MsgBox "ok"
    End If
  Else
    MsgBox "Brand does not exists"
    TextBox2.SetFocus
  End If
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi abdelfattah. I'm guessing that when U code textbox2.setfous, that fires your textbox3 exit event which causes the textbox3 exit code to run again. Also, U have missed the ".Value" in this part of your code. HTH. Dave
Code:
Set f = Sheets("sheet1").Range("B:B").Find(TextBox2.Value, , xlValues, xlWhole)
  If Not f Is Nothing Then
    If f.Offset(, 1) < TextBox3.Value Then
 
Upvote 0
hi, NdNoviceHlp actually i found out where is the problem cancel is should false not true whether your updating or my original code the problem is same thing also when change is false they are both work ,do you have any idea for
what works function cancel ? actually this code is not mine
 
Upvote 0
Solution

Forum statistics

Threads
1,214,793
Messages
6,121,617
Members
449,039
Latest member
Mbone Mathonsi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top