DLookUp Function Issues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Birky
    New Member
    • Dec 2006
    • 52

    DLookUp Function Issues

    Can someone please help me with my syntax below? I am trying to enable an object on a form for specific users only and in doing so I am trying to use the DLookUp function to try and keep it sweet and simple. I have created a table named “Employees” where I plan to add the people that will have access to the particular object (named CmdProjReport). The table is very basic just housing the below info:

    Employees Table:

    [HTML]
    KeyID EmployeeID Name Phone
    1 mibi Mike 7140
    2 kluck Kath 3165
    3 bobt Bob 5424
    [/HTML]

    Now I plane to execute the logic upon the loading of the form and I have come up with the below which as you can guess is not working. Can you help construct the below code to use the environments username and check to see if it exists in the Employees table and if so then enable the object? Any help would be greatly appreciated. (Not sure why I am having soooo much difficulty with the DLookUp syntax but I have tried everything I can think of and I can get it to work)

    Code:
    Private Sub Form_Load()
        Dim PrimId As Variant
                
        PrimId = DLookup("[KeyId]","Employees","[EmployeeID]=Environ("username"")
    
        If PrimId = Null Then
            CmdProjReport.Visible = True
        End If
    End Sub

    Thanks for the help
    Birky
  • dima69
    Recognized Expert New Member
    • Sep 2006
    • 181

    #2
    Originally posted by Birky
    Can someone please help me with my syntax below? I am trying to enable an object on a form for specific users only and in doing so I am trying to use the DLookUp function to try and keep it sweet and simple. I have created a table named “Employees” where I plan to add the people that will have access to the particular object (named CmdProjReport). The table is very basic just housing the below info:

    Employees Table:

    [HTML]
    KeyID EmployeeID Name Phone
    1 mibi Mike 7140
    2 kluck Kath 3165
    3 bobt Bob 5424
    [/HTML]

    Now I plane to execute the logic upon the loading of the form and I have come up with the below which as you can guess is not working. Can you help construct the below code to use the environments username and check to see if it exists in the Employees table and if so then enable the object? Any help would be greatly appreciated. (Not sure why I am having soooo much difficulty with the DLookUp syntax but I have tried everything I can think of and I can get it to work)

    Code:
    Private Sub Form_Load()
        Dim PrimId As Variant
                
        PrimId = DLookup("[KeyId]","Employees","[EmployeeID]=Environ("username"")
    
        If PrimId = Null Then
            CmdProjReport.Visible = True
        End If
    End Sub

    Thanks for the help
    Birky

    If PrimId = Null expression will never act as TRUE, because (Null = Null) = Null.
    To execute the command when PrimeId is Null, use this syntax:
    [CODE=vb]If IsNull(PrimId) Then
    CmdProjReport.V isible = True
    End If[/CODE]

    Comment

    • Jim Doherty
      Recognized Expert Contributor
      • Aug 2007
      • 897

      #3
      Originally posted by Birky
      Can someone please help me with my syntax below? I am trying to enable an object on a form for specific users only and in doing so I am trying to use the DLookUp function to try and keep it sweet and simple. I have created a table named “Employees” where I plan to add the people that will have access to the particular object (named CmdProjReport). The table is very basic just housing the below info:

      Employees Table:

      [HTML]
      KeyID EmployeeID Name Phone
      1 mibi Mike 7140
      2 kluck Kath 3165
      3 bobt Bob 5424
      [/HTML]

      Now I plane to execute the logic upon the loading of the form and I have come up with the below which as you can guess is not working. Can you help construct the below code to use the environments username and check to see if it exists in the Employees table and if so then enable the object? Any help would be greatly appreciated. (Not sure why I am having soooo much difficulty with the DLookUp syntax but I have tried everything I can think of and I can get it to work)

      Code:
      Private Sub Form_Load()
          Dim PrimId As Variant
                  
          PrimId = DLookup("[KeyId]","Employees","[EmployeeID]=Environ("username"")
      
          If PrimId = Null Then
              CmdProjReport.Visible = True
          End If
      End Sub

      Thanks for the help
      Birky

      Altered to suit it will work now

      Jim

      Code:
      Private Sub Form_Load()
          Dim PrimId As Variant
          Dim strusername As String
          strusername = Environ("USERNAME")
         
          PrimId = DLookup("[KeyId]", "Employees", "[EmployeeID]='" & strusername & "'")
          
          If IsNull(PrimId) Then
              cmdProjReport.Visible = True
          End If
      
      End Sub

      Comment

      • Birky
        New Member
        • Dec 2006
        • 52

        #4
        You all are life savers, and thanks for helping me out with this one. As you can see I have a lot to learn and I’m thankful you all are willing to teach.

        Have a great weekend..
        Birky

        Comment

        Working...