Improve company productivity with a Business Account.Sign Up

x
?
Solved

Date Picker problem

Posted on 2012-03-20
17
Medium Priority
?
434 Views
Last Modified: 2012-03-26
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?
0
Comment
Question by:TownTalk
  • 8
  • 7
  • 2
17 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 37743045
I think you should be able to use the textbox's Change event procedure to set the focus to the button.
0
 

Author Comment

by:TownTalk
ID: 37743082
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.
0
 
LVL 77

Accepted Solution

by:
peter57r earned 2000 total points
ID: 37743133
If isdate(me!textboxname.text) then me.buttonname.setfocus
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 

Author Comment

by:TownTalk
ID: 37743198
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.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37743310
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...)
0
 
LVL 77

Expert Comment

by:peter57r
ID: 37743329
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.
0
 

Author Comment

by:TownTalk
ID: 37743374
@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.
0
 
LVL 77

Expert Comment

by:peter57r
ID: 37743410
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?
0
 

Author Comment

by:TownTalk
ID: 37743481
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
0
 
LVL 77

Expert Comment

by:peter57r
ID: 37743566
You are not using the .text property.
0
 

Author Comment

by:TownTalk
ID: 37743660
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()
                   
    Me![DateRequired].SetFocus
    If IsDate(Me![DateRequired].Text) Then Me![SaveButton].SetFocus
       
End Sub

But it still gives me error 2185
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37743716
<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....
0
 
LVL 77

Expert Comment

by:peter57r
ID: 37743717
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)
0
 

Author Comment

by:TownTalk
ID: 37744443
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
0
 

Author Comment

by:TownTalk
ID: 37765125
This question seems to have dried up. I dont have a solution yet. Anyone got any other suggestion?
0
 
LVL 77

Expert Comment

by:peter57r
ID: 37765185
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.
0
 

Author Comment

by:TownTalk
ID: 37766006
@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.

Ian
0

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Beware when using the ListIndex and the Column() properties of a listbox in Access 2007.  A bug has been identified in the Access 2007 listbox code which can cause the .ListIndex property to return a -1, and the .Columns(#) property to return a NULL…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question