Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro executing twice??
I am trying to test the input value of textboxes in a userform. The correct
value to be entered is 1, 2, 3, or 4. There are four textboxes that execute the MSValidate routine. The routines work and the incorrect entries are caught but the problem is that both routines (see below) execute twice before actually returning to the textbox to accept correct entry. I had placed msgboxes throughout both routines to follow the flow. Because I was not familiar with the CHANGE() event, I had inserted an IF-THEN statement in the MSValidate routine to catch a negative number, not knowing that as soon as I entered the "-" part of the neg number, the CHANGE event executed. If you can direct me to a better way to trap entries other than a 1-4, please let me know. Private Sub TextBox6_Change() Dim TB As Integer TB = 6 MSValidate (TB) End Sub Sub MSValidate(TB As Integer) Dim MSQty, Config, Morphine, Ans, Ans1, NegNum As Integer MSQty = Worksheets("Items").Range("Z3") ' Get MAX quantity of Morphine Select Case TB Case 6 Morphine = Val(TextBox6.Value) Case 7 Morphine = Val(TextBox7.Value) Case 8 Morphine = Val(TextBox8.Value) Case 9 Morphine = Val(TextBox9.Value) End Select NegNum = 0 'MsgBox Morphine If Morphine <= 0 Then Config = vbOKOnly + vbExclamation Ans1 = MsgBox("Invalid Quantity. Please enter a 1 - " & MSQty, Config) NegNum = 1 GoTo Resetboxes End If If Morphine MSQty Then Config = vbOKOnly + vbExclamation Ans = MsgBox("Max quantity for Morphine is " & MSQty, Config) If Ans = vbOK Then GoTo Resetboxes End If End If Resetboxes: Select Case TB Case 6 TextBox6 = "" TextBox6.SetFocus Case 7 TextBox7 = "" TextBox7.SetFocus Case 8 TextBox8 = "" TextBox8.SetFocus Case 9 TextBox9 = "" TextBox9.SetFocus End Select End If Morphine = 0 NegNum = 0 End Sub Any ideas of why both execute twice? Thanks, Les |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Executing a macro | Excel Programming | |||
Executing Macro Help | Excel Programming | |||
executing a macro within another | Excel Discussion (Misc queries) | |||
Preventing macro from .xlt from executing in a .xls | Excel Programming | |||
What macro is executing? | Excel Programming |