Checking a string field for "N/A" or "n/a"

atrium

Registered User.
Local time
Today, 15:00
Joined
May 13, 2014
Messages
348
I'm sure this is a very simple one.
I'm checking an ABN number field. The user can put in 11 digits or N/A
here is the code
Code:
   If Len(Me.AbnFld) = 11 Then
      Me.AbnFld.InputMask = "00\ 000\ 000\ 000;;_"
   Else
      If Me.AbnFld = "N/A" Or "n/a" Then
         Exit Sub
      Else
        MsgBox " The ABN number must be filled in with the 11 digit mobile number or N/A"
        Me.AbnFld.SetFocus
        Exit Sub
      End If
   End If

AbnFld source is a short text field

My logic is there is three options.

11 digits - OK
N/A or n/a - OK
A mixture of both alpha and numeric or less than 11 digits - should show the MsgBox and setFocus

There is no input mask on the field in the form controls


My error is
If I put 23456 or anything less than 11 digits it creates an Run Time error 13 type mismatch. Same if I put in N/A
If I put in 12345678901 all is ok and it formats the field as required'

Any Help will be appreciated
 
This is not a valid boolean expression...
Code:
Me.AbnFld = "N/A" Or "n/a"
In this situation you have to compare the field to the string, and if there is another comparison, you need to compare the field again, like...
Code:
Me.AbnFld = "N/A" Or Me.AbnFld = "n/a"
...except string comparisons like this are case insensitive, (unless you have Option Compare Binary at the top of your module (default is Option Compare Database)) so you could just do...
Code:
Me.AbnFld = "N/A"
hth
 
Thanks Mark, it was a stupid over sight.

Cheers

atrium
 

Users who are viewing this thread

Back
Top Bottom