date Question!

G

Guest

I have a text box that I have to input todays date that is when I input data
which is by default date(), and I also have another text box that is supposed
to change if I do any changes in the form to todays date. Do I have to
program it so that when I change anything in the form, the date will
aoutmaticaly change to todays date and if I dont; change the record the last
date I worked on should still be there which is in the past?
 
D

Dirk Goldgar

JOM said:
I have a text box that I have to input todays date that is when I
input data which is by default date(), and I also have another text
box that is supposed to change if I do any changes in the form to
todays date. Do I have to program it so that when I change anything
in the form, the date will aoutmaticaly change to todays date and if
I dont; change the record the last date I worked on should still be
there which is in the past?

For the first text box, which I guess is for the date the record is
created, you can just set the Default Value property to Date(). Maybe
you already did that. For the second one, the "modified date", you need
to put code in the form's BeforeUpdate event to pick up the date just
before the record is saved; e.g.,

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.DateModified = Date

End Sub
 
W

Wayne Morgan

The Default Value will only give you a value for a new record. It has no
effect when you edit the record. If you want the date updated to today's
date when the record is edited, then in the form's BeforeUpdate event, set
the textbox to today's date. This will automatically change the date just
before the record is saved. If the user cancels the changes, nothing will
happen.
 
G

Guest

Thanks, that worked but unfortunatly the person that developed the db before
me, used the reserved word Date, so the when the records is being saved it
saves the last date saved as the Date which happens to be the date the rqst
was rcvd.

How do I go about this?
 
D

Dirk Goldgar

JOM said:
Thanks, that worked but unfortunatly the person that developed the db
before me, used the reserved word Date, so the when the records is
being saved it saves the last date saved as the Date which happens to
be the date the rqst was rcvd.

Argh! Now we see why it's a bad idea to use reserved words.
How do I go about this?

Try this:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.DateModified = VBA.Date

End Sub
 
G

Guest

Thanks alot that helped, I Learnt something.

Dirk Goldgar said:
Argh! Now we see why it's a bad idea to use reserved words.


Try this:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me.DateModified = VBA.Date

End Sub

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
G

Guest

Hello!
This post was VERY helpful! Along the same line, how would I go about
having this modified date field updated when I make a change to a subform?

Thank You!
 
G

Guest

Well, after a bit more of the old 'trial and error' routine, I managed to get
the 'DateModified' field to update if I placed the code in the subform's
AfterUpdate event.

Thanks anyway! I am just glad that a place exists where I can ask questions
and get answers, or at least pointed in the right direction.
 
D

Dirk Goldgar

Kirk Leader said:
Well, after a bit more of the old 'trial and error' routine, I
managed to get the 'DateModified' field to update if I placed the
code in the subform's AfterUpdate event.

Thanks anyway! I am just glad that a place exists where I can ask
questions and get answers, or at least pointed in the right direction.

I just saw your post today. I'm glad you figured it out -- it sounds
like you came up with the answer I would have given.
 
G

Guest

I tried the same for a combo box ... boy, did that mess things up! Anyway, I
discovered that placing the code in the 'Change' section works.

Thanks Again
 
D

Dirk Goldgar

Kirk Leader said:
I tried the same for a combo box ... boy, did that mess things up!
Anyway, I discovered that placing the code in the 'Change' section
works.

I don't know exactly what you tried this time, but be aware that you
*usually* don't want to use the Change event of a control if you can use
the AfterUpdate event. If the user types in the control, as opposed to
choosing an item using the mouse, the Change event fires for every
keystroke.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top