By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,573 Members | 907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,573 IT Pros & Developers. It's quick & easy.

Need Codes when field1 is changed, field2 will change to =field1

P: n/a
Problem #1:

I have a form, which says, has 2 fields: F1 & F2 (both Dates). I want
to be able to change F1 and F2 will change to be the same as F1 in the
codes. However, I will still be able to change F2 at anytime if needed
and changes in F2 will not affect F1.
Problem #2:

How to set default value of F1 to stay the same as the value of F1 in
previous record until otherwise changed manually?
Thanks in advance,
Perry

Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
#1. In the AfterUpdate event of the first control, set the value of the
second control to the first one.

Example:
Me.txtF2 = Me.txtF1

Or, if you want the value that was in F1 to be "moved" to F2
Me.txtF2 = Me.txtF1.OldValue

#2. In the AfterUpdate event of the control, set the control's Default Value
to the current value of the control.

Example:
Me.txtF1.DefaultValue = Me.txtF1

This will set the default value to the last value entered into txtF1. It
won't set it each time you move from record to record.

--
Wayne Morgan
MS Access MVP
<pe******@yahoo.com> wrote in message
news:10**********************@z14g2000cwz.googlegr oups.com...
Problem #1:

I have a form, which says, has 2 fields: F1 & F2 (both Dates). I want
to be able to change F1 and F2 will change to be the same as F1 in the
codes. However, I will still be able to change F2 at anytime if needed
and changes in F2 will not affect F1.
Problem #2:

How to set default value of F1 to stay the same as the value of F1 in
previous record until otherwise changed manually?
Thanks in advance,
Perry

Nov 13 '05 #2

P: n/a
Wayne,
This is what I had, but it does not seem to refresh. I even added
the line Me.Refresh but still none. Please advice again.

Private Sub SOCDate_AfterUpdate()
Me.Date2 = Me.Date1

End Sub
Sincerely,
Perry

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

P: n/a
> Private Sub SOCDate_AfterUpdate()
Me.Date2 = Me.Date1
It appears that the name of the control is SOCDate, not Date1. Make the same
correction for Date2.

--
Wayne Morgan
MS Access MVP
"Perry Cheng" <pe******@yahoo.com> wrote in message
news:41**********************@news.newsgroups.ws.. . Wayne,
This is what I had, but it does not seem to refresh. I even added
the line Me.Refresh but still none. Please advice again.

Private Sub SOCDate_AfterUpdate()
Me.Date2 = Me.Date1

End Sub

Nov 13 '05 #4

P: n/a
Sounds like the names of your controls in your code are wrong. You
want F2 to be the same as F1 whenever F1 is changed, so assuming on
your form, you need the following code:

Private Sub SOCDate_AfterUpdate()
Me.Date2 = Me.SOCDate
End Sub

the above line containing Date2 will need to be changed to whatever
you named the 2nd date field on the form - also double check the
SOCDate name - i'm just going by what you posted. This should solve
your problem. I'm suprised you didn't get a method or data member not
found error when trying to update the fields. Me.refresh isn't
needed. Post back if you still have problems.

I have a form, which says, has 2 fields: F1 & F2 (both Dates). I want
to be able to change F1 and F2 will change to be the same as F1 in the
codes. However, I will still be able to change F2 at anytime if needed
and changes in F2 will not affect F1.
Perry Cheng <pe******@yahoo.com> wrote in message news:<41**********************@news.newsgroups.ws> ... Wayne,
This is what I had, but it does not seem to refresh. I even added
the line Me.Refresh but still none. Please advice again.

Private Sub SOCDate_AfterUpdate()
Me.Date2 = Me.Date1

End Sub
Sincerely,
Perry

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #5

P: n/a
Thanks guys, I figured it out now. What happened was I had an onclick
event to open up a calender, then by pick a value on the calender, it
was sent back to the SOCDate (which I renamed it here for simplicity
sake, but then, I forgot to change the event name! Sorry) By doing so,
it did not update Field2 even SOCDate changes... anyway, I had to ask
the pop up calender to send the value to SOCDate and then setfocus on
Field2 instead.

Thanks again.
Perry

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.