Validation rule?

  • Thread starter Thread starter KLR
  • Start date Start date
K

KLR

I have created a field that prompts users for an analysis code from a
dropdown list of letters (A, B, C etc). I want a message to appear
when they select 'C' stating "Please ensure you have entered an enquiry
number...". How do I do this?
 
Why not just check and see if they have entered an inquiry number? Just run
code before they move to the next record that checks to see if the dropdown
contains a C. If it does, look at the inquiry number field. If it is
blank, pop up a msg box, take the cursor to the inquiry number field, and
cancel the move to the next record.

This type of validation or conditional requirement is pretty common. You
could do a search and read them many previous posts on the topic if you need
more details on how to write the code.
 
Unfortunately I am very new to code and currently learning it so don't
know how to start with this.

I am thinking that I need something along these lines:-

Private Sub Analysis_Code_AfterUpdate()

If Forms![f_R&S timesheets]![Analysis Code] = "C" And [Projects /
enquiry number] = "" Then MsgBox "Please enter an enquiry number",
vbOKOnly
End If

End Sub

But that doesn't work - comes up with an "End If without block If"
error message.
 
First, go back and remove anything other than alphanumeric characters from
field names. If you are already in f_RS_Timesheets you just need a
reference to the field or control, not the full Forms!etc. The code should
probably be in the form's Before Update event. Perhaps something like:

If Me.AnalysisCode = "C" And Me.EnquiryNo = "" Then
msgbox "Your message here"
End If

However, there is a difference between a Null value and a zero-length
string. See Help for more on this. You may wish to disallow zero-length
strings (in table design view), and change the code to:

If Me.AnalysisCode = "C" And IsNull(Me.EnquiryNo) Then
msgbox "Your message here"
End If

Note that there is a format you need to follow with the code. For instance,
"Then" is at the end of a line. As far as I know you shouldn't try to
follow it with anything else on the same line.
 
Back
Top