Date Picker problem

This is only a little gripe, but the people using my application would like it fixed if possible....

A data entry form has a Text Box in which a date is entered. This is the last control on the form before they click a command button in order to save the record.

Most users will use the date picker in order to select the date. But when they choose a date, the date appears in the text box, but the cursor is still flashing in there indicating the value has not been commited into the box.

The users will normally click the date picker to select a date, then click the Save Button to save the record. What they are finding is that they have to click the Save Button twice. The first click commits the date which has been selected by the date picker, then the second click fires my OnClick event handler for the Save Button.

Is there any way that I can force the date picker to commit the value into the text box so that is not sat there waiting to be entered?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I think you should be able to use the textbox's Change event procedure to set the focus to the button.
TownTalkAuthor Commented:
I could very easily do that if everyone used the data picker, but sometimes a user will type a date manually. The Change event cannot test the contents of a control while it is being edited. So I have no means of knowing when the control contains a valid date.
If isdate(me!textboxname.text) then me.buttonname.setfocus

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

TownTalkAuthor Commented:
That's interesting.... In the Change event I had already tried:

If isdate(me!textboxname) then me.buttonname.setfocus

I tried putting .text on the end of the control name:

If isdate(me!textboxname.text) then me.buttonname.setfocus

 and now it gives me the error:

You can't reference a property or method for a control unless the control has the focus.

This is an unbound form by the way. I dont know if that makes any difference.
Jeffrey CoachmanMIS LiasonCommented:
1. What the need for a "Save" button anyway..?
In Access the records are saved automatically...

2. What code are you using for this "Save"

3. Just for fun, I tried your setup, and it worked fine...
(No need to click save twice...)
I wouldn't expect using an unbound control to make any difference.
The message doesn't really make any sense if you are in the change event for the textbox containing the date - the textbox must have the focus in that situation.
TownTalkAuthor Commented:
@boag200 No the records are not saved automatically. This is an unbound form. I have some code which takes the form data and updates the SQL Server.

@Peter57r: Yes the Textbox has the focus at this time. So it would appear to be a misreported error. But can I ask please, are you under the impression that the change event should be able so see the contents of a text box while it is being edited? I thought that only the BeforeUpdate event could do this.
The change event sees every character entered, provided you use the .text property.

I have now built a simple test form here and I can't re-create your problem at all.  Are you sure you don't have other code running that is affecting the process?
TownTalkAuthor Commented:
I tried this simple code:

Private Sub DateRequired_Change()
    Debug.Print Me![DateRequired]
End Sub

each time I press a key, the full previous value of the field is written to the immediate window. The new value I am typing is not displayed at all. So I think maybe the problem is caused by it being an unbound form
You are not using the .text property.
TownTalkAuthor Commented:
Yes you are correct, but as we know, I get an error if I use the .text property

I tried this:

Private Sub DateRequired_Change()
    If IsDate(Me![DateRequired].Text) Then Me![SaveButton].SetFocus
End Sub

But it still gives me error 2185
Jeffrey CoachmanMIS LiasonCommented:
<No the records are not saved automatically. This is an unbound form. I have some code which takes the form data and updates the SQL Server.>
Oh, OK....
You have said that this  is an unbound control, yes?  Then I can't see how this error arises.

If it were bound then you must distinguish between the textbox name ans the controlsource name by changing the name of the textbox to say, txtDateRequired (and that will affect the event procedure name, of course)
TownTalkAuthor Commented:
No it's a completely unbound form. Nothing is bound. I have a routine which populates the controls with data from the Sql Server, and another routine which writes any changed data back afterwards.

Sorry for the delay replying. It's evening here now, so I am on my home pc
TownTalkAuthor Commented:
This question seems to have dried up. I dont have a solution yet. Anyone got any other suggestion?
I think you will have to post a sample file which shows the problem.

As I said earlier i can't reproduce the problem.  The .text property works fine for me in a Change event.
TownTalkAuthor Commented:
@Peter: I created a sample database with just a Text Box and a Save Button. It didn't have the problem. So I imported my Sales Order form from the main application. It also worked perfectly.

So I went back to my main application and Decompiled, Repaired and compacted it, and the problem went away. I hate it when that happens

So now your suggestion for the Change event works. Thank you for your help.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.