Using DLookup to Reference Multiple Tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • toadmaster
    New Member
    • Aug 2009
    • 45

    Using DLookup to Reference Multiple Tables

    I am trying to get an onclick event to open a form based on the logged in username from Windows.

    The idea is to open either form A or B after I have used DLookup to check a table to see if the user can be found in the table?

    If the user is not found in the table then open form B

    DoCmd.Minimize
    Text19 = DLookup("[username]", "Service", "[windowsname] = text17") Then
    DoCmd.OpenForm "Assign ", acNormal, , , , , Me.Number
    Else
    DoCmd.OpenForm "Manager", acNormal, , , , , Me.Number
    End If


    The other thing is; I am passing a value from the previous form in which the button was clicked (That value is holding the record number for the record being used)

    Private Sub Form_Open(Cance l As Integer)
    If Not IsNull(Me.OpenA rgs) Then
    Me.Number.Value = Me.OpenArgs
    Me.Requery
    End If
    End Sub

    The main purpose is to allow only a select group of people found in the table to submit a request to a particular individual and for those not found in the table submit it to another individual.

    Thanks any help will be appreciated
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Code:
    if nz(Dlookup("KEY_User","[myTable]","tx_UserName='" & Environ("UserName") & "'"),"")<>"" then
      'OpenForm
    else
      'OpenOtherForm
    
    End If
    Environ("UserNa me") will fetch the windows username for you.
    Dlookup will try to find the KEY_User by comparing windows username to username stored in table field tx_UserName (in my example) and return the key, or null, if it can't find it. Thats why I added the nz() function, in case null is returned.

    Comment

    • toadmaster
      New Member
      • Aug 2009
      • 45

      #3
      Worked like a charm; thank you so much........... ..

      Comment

      Working...