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

Validation based on a Null condition problem

kobamfo
P: 14
Hi Guys,
I have the following code which checks for non-Null fields prior to table update, so naturally, I have it on Before_Update of my form.

Expand|Select|Wrap|Line Numbers
  1. Dim strMessage As String
  2.     Dim intOptions As Integer
  3.     Dim strTitle As String
  4.     Dim bytChoice As Byte
  5.  
  6.     If IsNull(destname) Then
  7.         strMessage = "You have not entered a Destination for this Record." & _
  8.         "Input a destination to continue" & vbCrLf & vbCrLf & _
  9.         "Click ok to return to form."
  10.         intOptions = vbOKOnly
  11.         strTitle = "Missing Data..."
  12.         bytChoice = MsgBox(strMessage, intOptions, strTitle)
  13.  
  14.         'If bytChoice = vbOKOnly Then
  15.             'Set focus to the destname field            destname.SetFocus
  16.  
  17. 'highlight empty field
  18.  
  19. Dim Green As Long
  20. Green = RGB(229, 238, 124)
  21. destname.BackStyle = 1
  22. destname.BackColor = Green
  23.  
  24.             'Cancel saving the record
  25.             Cancel = True
  26.         'End If
  27.     End If
Now I want this validation to work ONLY WHEN a field named "docref" Is Null and "destname" is also Null. If "docref" Is Not Null, then the validation should not pop-up and allow the form to save with "destname" being Null or zero length. (offcourse the backend table allows for zero lenght for the "destname" field. I hope my question is clear. :-|
Any ideas please.
Oct 23 '12 #1

✓ answered by Rabbit

Use the AND operator.
Expand|Select|Wrap|Line Numbers
  1. If expression1 AND expression2 Then
  2.    Do Something
  3. End If

Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,366
Use the AND operator.
Expand|Select|Wrap|Line Numbers
  1. If expression1 AND expression2 Then
  2.    Do Something
  3. End If
Oct 23 '12 #2

kobamfo
P: 14
Thanks Rabbit, I think I am catching up a day at a time :-).
Oct 24 '12 #3

Post your reply

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