Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 1

Status
Not open for further replies.

carpetbelly

Technical User
Jun 12, 2003
202
GB
I keep getting a Run-Time error '424' on the following bit of code. Weird thing is I am positive I had it working pre xmas. I guess I didn't and I'm just still drunk from xmas lol

Code:
Private Sub Form_Load()
Dim adminWin As String
Dim adminTab As String
Dim Str As String

adminWin = Environ("username")

If DLookup("[UserName]", "qryAdmin", "[UserName] = '" & adminWin & "'") Is Null Then
    Str = "NA"
Else
    Str = DLookup("[UserName]", "qryAdmin", "[UserName] = '" & adminWin & "'")
End If

adminTab = Str

If adminWin = adminTab Then
    lblAdmin.Visible = True
    cmdAdmin.Visible = True
Else
    lblAdmin.Visible = False
    cmdAdmin.Visible = False
End If

End Sub

I get the error on the first DLookup line btw. I've run out of ideas.
 
Replace:

Code:
If DLookup("[UserName]", "qryAdmin", "[UserName] = '" & adminWin & "'") Is Null Then

With:

Code:
If IsNull(DLookup("[UserName]", "qryAdmin", "[UserName] = '" & adminWin & "'")) Then

Ed Metcalfe.

Please do not feed the trolls.....
 
You may replace this:
If DLookup("[UserName]", "qryAdmin", "[UserName] = '" & adminWin & "'") Is Null Then
Str = "NA"
Else
Str = DLookup("[UserName]", "qryAdmin", "[UserName] = '" & adminWin & "'")
End If

with this:
Str = Nz(DLookup("[UserName]", "qryAdmin", "[UserName] = '" & adminWin & "'"), "NA")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya carpetbelly . . .

. . . and [blue]cleaning up the code[/blue] we have:
Code:
[blue]   Dim Cri As String, flg As Boolean
   
   Cri = "[UserName] = '" & Environ("username") & "'"
   If Not IsNull(DLookup("[UserName]", "qryAdmin", Cri)) Then flg = True
   
   lblAdmin.Visible = flg
   cmdAdmin.Visible = flg[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Some other good suggestions there as well which are good to know going forward. Thanks people :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top