"Tony Williams" <tw@tcp.invalid> wrote in message
news:bt**********@hercules.btinternet.com...
I have a check box called Loadtxt and when it is ticked I want the value
of a control called EmailDatetxt to be today's date. I am using this code in
the AfterUpdate event of the checkbox but it doesn't work.
If Me.Loadtxt = True Then
Me.EmailDatetxt.Value = Date
Else
Me.EmailDatetxt = Null
End If
Anyone any ideas?
TIATony Williams
I see no reason why that doesn't work and you don't say what does actually
happen. It may be that the code is no longer associated with the control
(this can happen when you are designing the form, re-naming controls, etc).
To check this, look at the form in design view and double-click the
check-box to view its properties, find the AfterUpdate event in the event
tab and click the ... to make sure this takes you to the code you think it
should. Next, make sure the code compiles and close your form saving any
changes.
Perhaps you would like to consider a standard naming convention for your
controls such as chkLoad for a checkbox and txtDate for a textbox. This
convention helps to make sure you don't have forms that have identical field
and control names which can cause confusion (but is how Access names its
controls by default).
Also, although not really necessary here you could have a standard
error-handling procedure so all of these subs that you write for the form's
controls all look, well ..., more standard. Eg
Private Sub chkLoad_AfterUpdate()
On Error GoTo Err_Handler
If Me.chkLoad = True Then
Me.txtEmailDate = Date
Else
Me.txtEmailDate = Null
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Sub