Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Location
    Cape Town
    Posts
    8

    Unanswered: validation without having to setfocus

    hi,

    i am having a problem with validation, everytime i want to check to see if the filed has an empty value before adding. the problem is that i get the error message saying the control must have focus. in my if statement i have more than one field to check.
    how can i set focus to more than one field, or is there another way.

    thanks
    simon

  2. #2
    Join Date
    Aug 2003
    Location
    Belgrade
    Posts
    68

    Re: validation without having to setfocus

    How do you check for empty fields?

    I use the IsNull function:

    If IsNull(SomeField) Then
    ...


    or (if space characters are unacceptable):

    If (Trim(SomeField & "")) = "" Then
    ...

  3. #3
    Join Date
    Sep 2003
    Location
    Cape Town
    Posts
    8
    i check by saying

    if txtLName.text = "" then
    msgbox("Please enter a last name")
    the problem comes with checking for multiple fields.
    i know the code but the error keeps coming up saying control needs to have focus

    i will try the method that you showed me

    thanks

  4. #4
    Join Date
    Aug 2003
    Location
    Belgrade
    Posts
    68
    Originally posted by sim01
    i check by saying

    if txtLName.text = "" then
    msgbox("Please enter a last name")
    the problem comes with checking for multiple fields.
    i know the code but the error keeps coming up saying control needs to have focus

    i will try the method that you showed me

    thanks

    You get the error message because in if txtLName.text = "" you have an assignment statement embedded in an if statement. This is the same as if you write:

    if (txtLName.text = "") Then

    Access tries first to assign "" to the txtLName.Text property. If you want to know what is contained in the the text box, you should use:

    if txtLName.Value = "" Then

    or

    if txtLName = "" Then

    Yes, I know, it is confusing :-)) One more trap: if the user doesn't type anything in an Access text box, its value is not an empty string, but Null. That is why the safest way to check blank fields is:

    if Trim(txtLName.Value & "") = "" Then

    It covers the cases when the field contains nothing, an empty string or only spaces. Watch for joking users that type only Tabs or other non-printable characters :-))

Posting Permissions

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