Solved

Date Picker problem

Posted on 2012-03-20
17
423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 total points
ID: 37743133
If isdate(me!textboxname.text) then me.buttonname.setfocus
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

623 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