VBA UserForm - stopping the Textbox Enter event from running when selecting the frame

NicholasPerkins

New Member
Joined
Jun 30, 2009
Messages
2
Hi everyone,

Long time reader, first time poster.

App/OS: Excel 2003/Windows XP

I am developing a VBA User form which contains three frames. Each frame contains a number of textboxes. Each textbox for date input has a textbox_Enter event which shows a date picker form (using the Calendar control).

However when I click on the frame or on a field in the form, the event triggers for the first tabindex textbox field (if it is a date field).

I understand that this is because when I click to enter the frame, Excel selects the first tabindex textbox first and then moves to the one I have selected.

This also occurs when I have a multipage form. When I move to a different page, the first field is selected and if it is a date textbox, the event fires.

The code I have written for the event isn't very complex:
Code:
Private Sub tbEndPhaseThree_Enter()
    SYS_generalCode.strActiveField = "tbEndPhaseThree"
    OpenDatePicker curValue:=Me.tbEndPhaseThree.Value
End Sub
I did consider using a Boolean variable to stop the event firing for the first time, however if I do select the first tabstop field it won't fire at all. And I would need a Boolean variable for each frame/page.

Another idea was to always have a tabindex of 0 on an item that won't trigger the event. It is a last straw really as it isn't elegant.

I'm at a loss, so any suggestions of directions to go in would be appreciated.

Thanks,
Nick
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Well I've had a response away from this board which I've used to solve my problem, so I thought I'd share it here.

Rather than using the _Enter event, I've used the DblClick() event for the textboxes. This is much more elegant, as users can select the current data and copy/paste to other places if they need to. A quick dblclick, or a keystroke (I also have a _KeyDown event) and they have the date selection form pop up for them.

The help came through Twitter by someone reading the issue here and knowing where to find me, so thanks for the help in a round about way.

Cheers,
Nick
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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