I have a form sets the value of a string called 'CurrentUser'. This is declared in a separate module like so:
Public CurrentUser as String
Sometimes I need to refer to the CurrentUser string, but it seems to keep disappearing, i.e. reseting back to null. This only seems to happen when I am using DLookup to fetch some information from a table:
CODE
Private Sub AddRemove_Click()
If DLookup("UserAccess", "tblUsers", "[UserID]=" & [color="red"]CurrentUser[/color] ) = "Admin" Then
DoCmd.OpenForm "frmUserManagement", acNormal
Else
MsgBox "You are not authorised to carry out user management functions.", vbExclamation, "Insufficient Authority"
End If
End Sub
If DLookup("UserAccess", "tblUsers", "[UserID]=" & [color="red"]CurrentUser[/color] ) = "Admin" Then
DoCmd.OpenForm "frmUserManagement", acNormal
Else
MsgBox "You are not authorised to carry out user management functions.", vbExclamation, "Insufficient Authority"
End If
End Sub
It works once, but if the user click the button again, is doesn't work as the string is null. Why does running this code reset the string? I can't see anywhere that it is being redefined - just referred to.
Thanks for any help.