INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Dlookup for multiple conditions

Dlookup for multiple conditions

(OP)
Hi,

A form's open event has run the following code successfully for years:

Private Sub Form_Open(Cancel As Integer)
If DLookup("Level", "USERS", "[USER ID] = '" & CurrentUser & "'") = 31 Then
DoCmd.RunMacro "Blah Blah Filter"
Else: DoCmd.RunMacro "Dog"
End If
End Sub


However, we now need to add a second level of 66 to run the macro "Blah Blah Filter"

We've tried the following, but it runs "Dog" for both levels, and any others:

If DLookup("Level", "USERS", "[USER ID] = '" & CurrentUser & "'") = 31 Then
DoCmd.RunMacro "Blah Blah Filter"
End If

If DLookup("Level", "USERS", "[USER ID] = '" & CurrentUser & "'") = 66 Then
DoCmd.RunMacro "Blah Blah Filter"

Else: DoCmd.RunMacro "Dog"
End If
End Sub


We've also tried changing = 31 to = (31,66) which doesn't work.

Your solution is greatly appreciated.

Thanks you!!

RE: Dlookup for multiple conditions

CODE -->

Private Sub Form_Open(Cancel As Integer)
 dim level as integer
 dim strWhere as string
 strWhere = "[USER ID] = '" & CurrentUser & "'"
 debug.print "Where: " &  strWhere
 'post back what this shows
 level = nz(DLookup("Level", "USERS", strWhere),0)
 debug.print "level " & level
 'post back what this shows
 If level = 31 or level = 66 Then
   DoCmd.RunMacro "Blah Blah Filter"
 Else
   DoCmd.RunMacro "Dog"
 End If
End Sub 

RE: Dlookup for multiple conditions

(OP)
Worked like a charm MajP.

Thanks so much!!

RE: Dlookup for multiple conditions

Did it really work? If it worked well, don't forget to mark it as a great post, so others can know the question was answered or at least there is useful information in the thread.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57

RE: Dlookup for multiple conditions

(OP)
Hi KJV1611,

I did mark it as a Great Post 3 days ago, at the same time I commented that MajP's code worked like a charm smile That is why the pink star appears beside the thread in the forum list. smile

RE: Dlookup for multiple conditions

Hmm, must've been short a Mtn Dew when I looked, then. blush Thanks for setting me straight. thumbsup

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close