Derived field Validation

S

steve

I am just learning to write VBA code and I am totally lost.



How would I go about adding validation to the below statement. I want to
check to be sure [End_time] is less then or equal to [close_time] on a
subform called [library_hours]. If it is not, I want to display a message.



Private Sub End_time_GotFocus()

Let Forms![schedule]![End_Time] = DateAdd("n", [Class_Length], [Start_Time])



End Sub





Thanks for the help
 
G

Graham R Seach

Steve,

I don't quite understand where these controls are located. You mention a
subform called library_hours, but I'm not sure if one or both controls are
on that subform. So I've given you the procedure for working it out, after
which, I've shown how to work out the fully qualified name for a control on
a subform. You should have no trouble modifying the code to suit.

If Nz(Me!End_time, IIf(Not IsNull(Me!close_time), Date, CDate(99998))) <=
Nz(Me!close_time, CDate(99999)) Then
MsgBox "Nope!"
End If

This takes into account the possibility of one or both controls being Null.

To work out the full qualified name of a control (in this case, close_time)
on a subform (from the main form):
Me!library_hours.Form!close_time

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 

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