Dlookup on form load (1 Viewer)

murray83

Games Collector
Local time
Today, 18:21
Joined
Mar 31, 2017
Messages
728
Afternoon folks

trying to change how some buttons are shown/hidden. at the moment they are shown based on the PC logon based on the Environ("username")

so its hard coded which i guess not the best way o do it as when need to add someone new to the list need to access the code and then add them on the end of this

Code:
If Me.txtusername.Value =

Me.cmdSYS.Visible = True
Me.cmdClose2.Visible = True
Else
Me.cmdSYS.Visible = False
Me.cmdExit.Visible = False
End If

End Sub

So thought about a table which would hold the login details for people who have access and also for people who may need it then use dlookup to see if the txtusername value matches to the table but hit an error, run time error '2428':

"You entered an invalid argument in a domain aggregate function"

this is my dllookup code

Code:
If txtusername = DLookup(PCLogin, tblSYSManger)

not sure but think i may be missing some punctuation but all help much appreciated

cheers
 

Minty

AWF VIP
Local time
Today, 18:21
Joined
Jul 26, 2013
Messages
10,366
Each user in your table should have an access level. Assuming if they are level 1 they can access stuff then it should read something like
Code:
Dim AccessLvl as Int

AccessLvl =  DLookup("AccessLvl", "tblSYSManger" , "[UserName] = '" & Environ("username") & "'")

If AccessLvl = 1 Then

Me.cmdSYS.Visible = True
Me.cmdClose2.Visible = True
Else
Me.cmdSYS.Visible = False
Me.cmdExit.Visible = False
End If
 

murray83

Games Collector
Local time
Today, 18:21
Joined
Mar 31, 2017
Messages
728
so sorry for the tripple post, but i have managed to fix it myself

im so happy

so what i did in the end was this ( i had been missing the criteria as i thought i could leave it out as thought the enviro name was the criteria to match against)

Code:
If txtusername.Value = DLookup("PCLogin", "tblSYSManager", "PCLogin = '" & Forms!Handover_Main!txtusername & "'") Or txtusername.Value = DLookup("ALTLogin", "tblSYSManager", "ALTLogin = '" & Forms!Handover_Main!txtusername & "'") Then

Me.cmdSYS.Visible = True
Me.cmdClose2.Visible = True
Else
Me.cmdSYS.Visible = False
Me.cmdExit.Visible = False
End If

End Sub
 

Users who are viewing this thread

Top Bottom