Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fill in one field when another field is filled

Status
Not open for further replies.

christak

MIS
Jul 14, 2003
20
US
I'm sure that there is a very simple answer for this, but I can't come up with it. I have zero programming experience and teach myself as I go along.
Anyway, I have a field called CO1. When a user enters the value for CO1 on the form, I want a field called Currentdate1 to automatically fill with today's date. How do I do this and please forgive the dumb question!
 
In the Exit Event of your CO1 field, you can add code to update the CurrentDate1 field.
Code:
Private Sub CO1_Exit(Cancel As Integer)
   Me.CurrentDate1.Text = Now
End Sub

Good Luck!
 
Thanks so much for the fast reply. I usually work through the properties box of the field, and the "On Exit" property requires a macro. How do I turn that code into a macro? The table's name is "Expedte", if that helps at all.
 
You don't have to use a Macro...in the properties box, when you click on the ellipsis button to the right of the On Exit field, you have the choice of Expression Builder, Macro Builder, or Code Builder. Select the Code Builder, and add the code.
 
I'm learning! Please bear with me if you can. Here's the most pathetic question of all...
What should I put in place of the Me in the code?
 
Also note that if the user happens to pass thru the CO1 control again at a later date, even without changing the entry for CO1, that the date in CurrentDate1 will be changed.

If the value in CO1 is never changed, and you always want to retain the original date in CurrentDate1, do something like this:

Private Sub CO1_Exit(Cancel As Integer)

If IsNull(Me.CurrentDate1) Or Me.CurrentDate1.Value = ""

Then

Me.CurrentDate1.Text = Now

End If

End Sub

This will only allow the date to be inserted if the CurrentDate1 field is empty.

On the other hand, if the value in CO1 is sometimes changed, and you want the date in CurrentDate1 to reflect this, place your code in the AfterUpdate sub like this:


Private Sub CO1_AfterUpdate(Cancel As Integer)

Me.CurrentDate1.Text = Now

End Sub

The Missinglinq

There's ALWAYS more than one way to skin a cat!
 
Me" refers to the current form, so you don't have to change it as long as you're dealing with just this one form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top