VBA form - ghost call to textbox exit sub

jpmccreary

New Member
Joined
Jul 21, 2010
Messages
11
I am experiencing a strange issue with one of my forms. The form collects customer info from the user using a multi page interface. On the 2nd tab I have a text box called tbEffectiveDate and two frames: Tax and Signature info. Inside the tax frame I have text boxes for business type, incorporated and tax id/ssn. For tax and ssn I have code for exiting to check the length and also format the number entered:

Private Sub tbTaxID_Exit(ByVal Cancel As MSForms.ReturnBoolean)

If IsNumeric(Val(tbTaxID.Value)) And Len(tbTaxID.Value) = 9 Then
tbTaxID.Text = Format(tbTaxID.Text, "00-0000000")
Else
MsgBox "Please enter a valid 9 digit tax id"

Cancel = True
End If

End Sub

When I exit tbTaxID this sub is not called. If I tab through all items and back around to the tbEffectiveDate this sub does get called after exiting, but only after tabbing through everything. I deleted the code for tbEffectiveDate but this still occurs. I also tried renaming the text boxes. How can these text boxes be linked with no code?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
The tbTaxID_Exit event isn't triggered when you select other objects in other frames. It's only triggered when you select other objects within the same Frame.

Try using the...
Code:
Private Sub tbTaxID_[COLOR="Red"]BeforeUpdate[/COLOR](ByVal Cancel As MSForms.ReturnBoolean)
...event instead.
 
Upvote 0
Great suggestion! After a little testing I believe the BeforeUpdate is going to work.

So it sounds like the Exit event was getting stored but not processed because I was moving from one frame to the next. Once I was out of the frames the event triggered at the first exit event.

I would never have realized what was happening without your help. Thank you very much.
 
Upvote 0

Forum statistics

Threads
1,215,551
Messages
6,125,478
Members
449,233
Latest member
Deardevil

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