Solved Control does not accept input until lose focus

foshizzle

Registered User.
Local time
Today, 12:36
Joined
Nov 27, 2013
Messages
277
I'm using Allen Browne's method #2 which filters a report based on two dates entered in a form. Its a simple form with only 2 unbound textbox controls and the one command button to open the report. The two controls have a default value of =Date().
Limiting a Report to a Date Range

The code works well. However, the problem I am having is that if I enter a new value on the start and end date controls then press the command button, the second date control does not actually update with the value. If click elsewhere on the form moving focus off the text control, it works fine. Is there a way to make this more seamless?
 
Hi. What is happening instead? Are you saying after you select a new date and click on the button, the date you selected goes back to what it was before you made the selection?
 
I haven't specifically created a test on my end to duplicate what Allen's code is, so here is just some generic advice.
For me, usually, once a button takes the focus (i..e, when clicked - if it's a regular command button control), that's sufficient to cause any textboxes' Text to become their Value (which is what you need IF you are always coding like Me.Controlname, instead of Me.Controlname.value or .text)

If you want to avoid this issue, one way (among many, probably), is to either adjust your code to look at the ControlName.Text, or, to code Me.Controlname.Value=Me.Controlname.text ... and then your original code continues.
 
Hi. What is happening instead? Are you saying after you select a new date and click on the button, the date you selected goes back to what it was before you made the selection?
I believe what is happening is, since the text box defaults to Date(), the new date is not accepted until focus is lost in that text box.
 
I believe what is happening is, since the text box defaults to Date(), the new date is not accepted until focus is lost in that text box.
But what is "physically" happening as you observe it? As I said, are you selecting a date from the calendar and see it physically change back to the current date?
 
I tested this and no problem with second textbox. Code gets the input. If you want to provide db for analysis, follow instructions at bottom of my post.
 
But what is "physically" happening as you observe it? As I said, are you selecting a date from the calendar and see it physically change back to the current date?
Actually I was typing in the date. The date does update in the control as I type but I noticed it does not “align” (format) itself as short date in the control if I hit the button before clicking off the text control. If that makes sense. I can upload a copy of it when I get back to the house.
 
Actually I was typing in the date. The date does update in the control as I type but I noticed it does not “align” (format) itself as short date in the control if I hit the button before clicking off the text control. If that makes sense. I can upload a copy of it when I get back to the house.
Yes, seeing it in action would be best. Please post a demo when you can. Thanks.
 
Not using a button control. It is an Image control. Use a button and will get desired behavior.

Otherwise, first set focus to another control, such as the start date textbox. Me.txtStartDate.SetFocus
 
Not using a button control. It is an Image control. Use a button and will get desired behavior.

Otherwise, first set focus to another control, such as the start date textbox. Me.txtStartDate.SetFocus
Bingo - hence my question,
For me, usually, once a button takes the focus (i..e, when clicked - if it's a regular command button control)

You can either code to set the focus somewhere else 'first' (then your original code continues - as June said, or you can code to force the control's Value to become its Text, or you can refer to its text instead of its value in your code.
But, given you have a Date and it needs to adjust its format just so ... (And, if you code does not provide for that...which it really should, using Format(Me.Controlname.Value,"mm/dd/yyyy") .... then do what June said and move focus somewhere else, first, explicitly.

Or you can probably skip all of that and just adjust your code to format the date control as needed - which your code should be covering anyway..
 
Not using a button control. It is an Image control. Use a button and will get desired behavior.

Otherwise, first set focus to another control, such as the start date textbox. Me.txtStartDate.SetFocus

This was going to be my failsafe option. Thanks for clarifying
 
Bingo - hence my question,

You can either code to set the focus somewhere else 'first' (then your original code continues - as June said, or you can code to force the control's Value to become its Text, or you can refer to its text instead of its value in your code.
But, given you have a Date and it needs to adjust its format just so ... (And, if you code does not provide for that...which it really should, using Format(Me.Controlname.Value,"mm/dd/yyyy") .... then do what June said and move focus somewhere else, first, explicitly.

Or you can probably skip all of that and just adjust your code to format the date control as needed - which your code should be covering anyway..
Thanks for the explanation; i was not aware of the difference between the image control vs an actual command button.
 

Users who are viewing this thread

Back
Top Bottom