By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,482 Members | 2,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,482 IT Pros & Developers. It's quick & easy.

Validation In Access?

P: 1
I'm trying to create a validation rule that will only allow a date after the date entered in a previous field.

For example.
I have 2 fields, 'Date Start School' and 'Date End School'
How do I create a validation rule that makes sure 'Date End School' is after 'Date Start School'


I don't know whether that makes sense to anyone, but any help would be appreciated.

Thanks in advance
Apr 14 '08 #1
Share this Question
Share on Google+
1 Reply


nico5038
Expert 2.5K+
P: 3,072
To test multiple fields I don't use a validation rule, as it's not sure which field will be filled first...
You need to know that the user is finished entering data before testing, that's why I always have a [Save] button to do all the testing. My code "behind" that button looks like:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSave_Click()
  2. Dim txtMessage As String
  3. On Error GoTo Err_btnSave_Click
  4.     ' init error message 
  5.     txtMessage = ""
  6.     ' Check fields in reverse order to set focus to the first
  7.     If Not Len(NZ(Me.Description)) > 0 Then
  8.         txtMessage = "Description empty ?" & vbCrLf
  9.         Me.Description.SetFocus
  10.     End If
  11.     If Not Len(NZ(Me.Severity)) > 0 Then
  12.         txtMessage = "No Severity?" & vbCrLf & txtMessage
  13.         Me.Severity.SetFocus
  14.     End If
  15.     If Not Len(NZ(Me.Type)) = 0 Then
  16.         txtMessage = "Recordtype empty ?" & vbCrLf & txtMessage
  17.         Me.Type.SetFocus
  18.     End If
  19.     ' Check error found
  20.     If Len(txtMessage) > 0 Then
  21.         MsgBox txtMessage
  22.         Exit Sub
  23.     End If
  24.  
  25.     DoCmd.Close
  26.  
  27. Exit_btnSave_Click:
  28.     Exit Sub
  29.  
  30. Err_btnSave_Click:
  31.     MsgBox Err.Description
  32.     Resume Exit_btnSave_Click
  33.  
  34. End Sub
  35.  
Here you can test first or both fields are filled and when they are, test for their relation.

Clear ?

Nic;o)
Apr 14 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.