Distinction if VBA or user enter textbox

Kamolga

Well-known Member
Joined
Jan 28, 2015
Messages
1,157
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:

jonathann3891

Board Regular
Joined
Apr 27, 2015
Messages
109
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
Try changing your textbox to an Exit event
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,351
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
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.
 

Kamolga

Well-known Member
Joined
Jan 28, 2015
Messages
1,157
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!
 

Forum statistics

Threads
1,082,295
Messages
5,364,359
Members
400,792
Latest member
Dxmiian

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top