Distinction if VBA or user enter textbox

Kamolga

Well-known Member
Joined
Jan 28, 2015
Messages
1,185
Hi,

I have 4 textboxes in a userform1. When I click in one of them
Code:
[LEFT][COLOR=#222222][FONT=Verdana]textbox1_enter[/FONT][/COLOR][/LEFT]
, I have a separate datepicker userform2 that shows and puts its value in the textbox. It took time but that works.

My issue is that when I initialize userform1, I would like to have specific dates in the textboxes
Code:
textbox1.value=Range("A1").value

but that launch my datepicker userform. I tried
Code:
[LEFT][COLOR=#222222][FONT=Verdana]textbox1_change [/FONT][/COLOR][/LEFT]
but have the same result.

I wish I could use the same the same effect as Application.EnableEvents=false to have the enter/change.

I have a button Ok, that I try to put focus on before and after without any success

Code:
BtnOK.SetFocus
Any idea is welcome :)
 
Last edited:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You have to use userform initialize for this:
My issue is that when I initialize userform1, I would like to have specific dates in the textboxes

Setting the "OK" button as default may do it for you.
I have a button Ok, that I try to put focus on before and after without any success
 
Upvote 0
Try changing your textbox to an Exit event
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
 
Upvote 0
You can use a control variable like Enableevents. Declare a boolean at the top of the userform module, then start each event with:

Code:
if boolean_variable then exit sub

Thus, whenever you want to stop controls from reacting to your code, simply set the variable to True, do what you need, then set it back to False.
 
Upvote 0
Thank you very much.

Setting the "OK" button as default may do it for you.
No luck on that one, it was on default.

The
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
works for me: indeed I have no datepicker showing up when I initialize userform1 anymore and I know how to get the datepicker but another user would type the date and when finished, would leave and activate the datepicker which would overwrite his date and become useless.

if boolean_variable then exit sub
that is the last one I tried and it works perfectly.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,215
Members
448,874
Latest member
b1step2far

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