Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2002
    Location
    Kansas City
    Posts
    103

    Unanswered: If.........then statement using VBA

    Can anyone assist me with the correct syntax for an If.....then statement using VBA? I've tried repeatedly but am unable to make this work. I'd like to evaluate a condition in either a select query or a make table. I've tried If [table name].[field name] <> "" then........
    and If "table name.field name" <> "" then.........

  2. #2
    Join Date
    Nov 2001
    Posts
    336
    Syntax:

    if ... then ...
    else
    endif

    IF statement won't work in queries. Try IIF() function instead.

    Igor

  3. #3
    Join Date
    Jun 2002
    Location
    Kansas City
    Posts
    103
    Thanks for the reply. Should I be able to evaluate a condition in a table? I'm not sure how I'd make the following routine work using the IIf function?

    If [Null Employee Location Code].[Emp ID] <> "" Then
    MsgBox "One or more employees are missing a cost center. See printed report."
    DoCmd.OpenReport "Employees Missing Location Code", PrintMode
    Else.................
    End If

  4. #4
    Join Date
    Nov 2001
    Posts
    336
    dim nCount as Integer

    nCount = NZ(DCount("[EmpID]","[Employee Location Code]", "[EmpID]=''"),0)

    if ncount > 0 then

  5. #5
    Join Date
    Jun 2002
    Location
    Kansas City
    Posts
    103

    Smile

    Thank you very much for the work-around! I understand the logic but wouldn't have arrived at it myself.

Posting Permissions

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