Link to home
Start Free TrialLog in
Avatar of gcgcit
gcgcit

asked on

autopopulate second field

See attached screenshot. When I enter the "From" date (by using the calendar control), I want the "To" textbox to automatically get filled in with 7 days after the "From" date.  I have this code and I know it works...

Me.toDate.Value = DateAdd("d", 7, Me.fromDate.Value)

I can't seem to find the right event for this to work.  The change event only works on the 2nd time it's been changed.  These are both unbound fields.
ee-daterange.jpg
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image


me.to=dateadd("d",7,Me.From)
place the codes in the lost focus, or exit event of textbox from
Avatar of gcgcit
gcgcit

ASKER

problem is... its the only thing you select on the form before press view report... so it sits empty until when you press view report
Try the On Enter event of your DateField From and place your code:

Me.toDate.Value = DateAdd("d", 7, Me.fromDate.Value)

HTH,
Daniel
I that dont work, place it on the OnExit event of your DateField...

Daniel
did you try it?
Avatar of gcgcit

ASKER

i've put it on all the events... none work right... its wierd.  Its almost like I have choice but to fire it from a button (which is annoying).  What I provided on the screen is the entire form... you just select one date, the 2nd one should autopopulate then you click view report.  OnExit or LostFocus only fire when I click View Report... I'll try to set the focus to the button maybe?
hi cap, hows it going


>> When I enter the "From" date (by using the calendar control),

did u try the afterupdate event of the calendar control?



Avatar of gcgcit

ASKER

rockiroads: its just the textbox in 2010 that pops up a calendar control... not sure i have control over it
howdi rocki,

the afterupdate will not fire when you assign a value from calendar control or from vba codes.
<OnExit or LostFocus only fire when I click View Report.>

so, what is your problem with this?
<ot>rocki, what have you been doing? </ot>
have u looked at the code behind this form? is there anything in formload that automatically brings up the cal control?
Avatar of gcgcit

ASKER

the problem is... the person clicks the "From" they aren't likely to press "view report" when the "To" field is still empty... so I'm trying to figure out a way to display it for them to prompt them that all information is entered but save them from figuring out what 7 days from the date they picked is
yo cap, been busy with job and apt hunting plus no internet at home. now I have internet :)
if they will accept a +7 days range for the report, just add it to the filter of your report

post the codes that you are using to open the report


 


So, this is really a question of esthetics.
The after update event will do what you want, and the report opens correctly, but you don't see the end date until you click the button.
Which is bothersome.

Am I correct?

So you are looking for something to change the second textbox, while the first still has the focus.
And the change event doesn't do it because the calendar control doesn't fire the Change event by itself.

The coding won't be elegant, but....
If you give your first textbox  OnGotFocus and OnLostFocus events that change the timer value from 0 to 250 (1/4 second) and back...
Then you could put your date add code in the Timer event and you should get your desired result.
Testing for null, and all those other nice things of course, should the user click in and then dally.

Catch my drift?
Avatar of gcgcit

ASKER

Nick67: It's totally esthetics... I'm digging that timer control idea.  What would the timer code be on the got focus event?

Here it is shimmed up for you.
timer.mdb
ASKER CERTIFIED SOLUTION
Avatar of Nick67
Nick67
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
But, on second thought, I am in Access 2003, with no calendar picker, so KeyPress may not work for your setup!
Nick:  The problem I'm having with an unbound Form is trying to find an event that fires after keyboarding in some data in a textbox and then pressing Enter.  If you bind the Form to a dummy table, the AfterUpdate event fires.  Unbind the form - no event.
Until you leave the control, the AfterUpdate doesn't fire.
This is exactly the problem.

The author would like to see the second control get a value 'before' leaving the control, because the user is clicking a button that opens a form next.
The control does get updated and the report works, but because the report covers over the form, the end user doesn't see the value before clicking, and has to take it on faith that the date range is what is expected.

<Unbind the form - no event. >
In the shim I posted, if you put an afterupdate event to fromDate

Private Sub fromDate_AfterUpdate()
MsgBox "I fired"
End Sub

and key something into fromDate and hit enter, it fires, so the form being unbound is not an issue in Access 2003 at least.
Are you asking something related to the author's problem and what I posted
<The problem I'm having with an unbound Form>
Or related to stuff you have done where you have had the same operational requirement?
I'm confused.
I have a small form, and a textbox.  The form is not bound.  The form is in the View mode, I type something in the textbox, press Enter, the cursor moves to the beginning of the entry in the text box.  I had placed a msgbox in the Afterupdate event of the textbox.  In my case, the AfterUpdate event did not fire when the form was not bound to a table.  It did fire when I made the control source of the form a local table.  I'm not making this up.  My previous comment was posted because of a similar requirement - but your results are at odds with what I experienced.  I'm running A2003 under XP Pro.
Only one control that can take the focus, maybe?
If there's nothing bound, and only one control, maybe the focus can't go anywhere else and so no afterupdate occurs?
If it's bound and only one control, then it'd go to a new record!
As a matter of fact, there was my test text box another text box, and two subforms each with a form as the source object.  Go ahead and try it.  Create a small form with two textbox controls.  Put the msgbox in the AfterUpdate event of one text box.  Open the form, type some data in the text box and press Enter - no message.  Now bind the form to any table - type in data and press enter - presto - the message.
I did try it.  With the very form I created and posted to this question.  Unbound.  No table in existence whatsoever.  I put in an afterupdate event.  Commented out all the other events.  Typed in 13-May-11.  Pressed enter.  My afterupdate event fired.  Why your db doesn't behave the same I don't know.  If you take the stub I posted and do the same, what happens?
Here it is, done up as described.
Works in Access 2003 and Access 2010
with an afterupdate event--this is not a solution for the author though!
timer.mdb
It's funny, the keypress event works so elegantly in Access 2003, but it doesn't give the right result in Access 2010, even if you type in the date manually.
I downloaded the stub at http:#a35762063.  I opened the form, typed in a date in the ToDate textbox, press Enter, and nothing happens.  If I move to the next text box or to the command button, the date in FromDate advances a week from that displayed in ToDate.  Question - who has the sick machine?
Well, given that the behavior I've noted happens on all of my domain machines, and my home machine, and in differing versions of Access, we have a mystery.
To all the other posters in this question:
If you download the stub, enter text in the textbox with the after update event and press enter, what happens?
On all my machines, an after update evnt occurs.
On @GRayL's machines, nothing occurs.

Please post what happens for you.

Thanks
Nick67
Since my db doesn't work for you, and it works for multiple machines in my control, but not in my domain, it has to be a global setting
 User generated image@GrayL,
Do you have 'Don't move' as a default?
No, but I had Next Record, and as there was no recordset, I guess it did not move.  I changed it to Next Field, and all became right with the world.  Very shrewd dude!  Thanks for sorting that out.
No Biggie.
Canucks helping Canucks
Albertans helping Albertans
Survivors of the meatgrinder known as U of A lending mutual aid.

Its all good!