Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check for a variety of values (2000)

    Hi,
    I need to check for specific values in a field and cannot for the life of me remember how to do it. It's something like this:
    If IsNull(Me.Address) & IfNotNull (Me.Postcode) Then
    MsgBox "Please enter a valid address!", vbOkOnly, "Error"
    Exit Sub

    This returns an error at IsNotNull, but essentially I would like to check that both these fields have been filled in.
    I'd also like to check as to whether these fields have more that 4 letters in them..............can't remember how to do this either.
    Thanks in advance!

  2. #2
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Check for a variety of values (2000)

    Hi,
    Try this: (It is untested by me)
    If IsNull(Me.Address) And Not IsNull(Me.Postcode) Then
    MsgBox "Please enter a valid address!", vbOKOnly, "Error"
    End If

    About your second query,
    You will need some function procedure using the LEN function to count characters in the field!
    Regards,
    Rudi

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Check for a variety of values (2000)

    If you want to check that both Address and PostCode have been filled in, i.e. issue a warning if either of them is null:

    <code>If IsNull(Me.Address) Or IsNull(Me.PostCode) Then
    MsgBox ...
    ...
    End If</code>

    If you want to check that the user has entered more than 4 characters, i.e. issue a warning if either has 4 or less characters:

    <code>If Len(Me.Address) <= 4 Or Len(Me.PostCode) <= 4 Then
    ...</code>

    This will only work if you checked for null values before. You can combine the tests like this:

    <code>If Len(Me.Address & "") <= 4 Or Len(Me.PostCode & "") <= 4 Then
    ...</code>

    By concatenating with "", you don't need to treat Null values separately.

  4. #4
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Norfolk, England
    Posts
    744
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check for a variety of values (2000)

    Thanks Hans, this is ideal. I've used the last function as this seems to be the most practical.
    Thanks for your guidance!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •