View Full Version : Auto populate static date/time


Patm
10-25-2001, 11:12 AM
I am developing a db for a phone log in regards to technical inquiries. The first control on the form is a combo box with a drop down for particular individuals. The next 2 controls are date and time text boxes. They both have their appropriate control sources of date and time.
What I would like to be able to do is have the date and time fields auto-populate with the current d&t as soon as the combo box is populated. I want these to be static, and to not update if someone goes back to that record.
Thanks for the help.

R. Hicks
10-25-2001, 11:26 AM
Set the Enabled property of both textboxes (txtDate and txtTime) to "No". Also set the Locked property of both to "Yes". This will keep the user from altering the entries.

Now use the After Update event of the combobox to populate the 2 txtboxes if it is a "New Record".

Private Sub YourComboName_AfterUpdate()
If Me.NewRecord And IsNull(Me.YourDateTxtbox) And IsNull(Me.YourTimeTxtbox) Then
* Me.YourDateTxtbox = Date()
* Me.YourTimeTxtbox = Time()
End If
End Sub

(change the names of the controls above to the names of your controls)

HTH
RDH

[This message has been edited by R. Hicks (edited 10-25-2001).]

Patm
10-25-2001, 11:39 AM
Very helpful!
One question. When I go into After Update event it brings up the dialogue box for the Expression, etc. Builder. Do I select Expression? Or am I entering the Private Sub... lines in somewhere else?
Pat