Question : declaring constant variables using if's and elsif's

I have a workgroup that stores userid's and pwd's, these are in the format of the user's windows nt logon id.

in a startup function, I'd like to parse the ID's into the person's name.

IE:

Public Function Startup()

If CurrentUser = "sgrafl01"
    const username as String = "Sean Graflund"
Elseif CurrentUser = "dmarti01"
    const username as String = "Donald Martin"
ElseIf .... and so on

End if

End Function

I have about 12 logon ID's I'd do this with.  It works fine with standard global strings, but I'd like to turn it into a constant.  For some reason, after using the DB for awhile the global string turns to a zero lengh string.  If I use a const string, it will always have it.

When I try to declare this as a constant, VBA gives a declaration declared multiple times error.  Is there a way I can assign this as a const without getting that error or will I have to change all the User ID's to the correct person's name in the workgroup manager instead of using the same ID as is used for the Windows NT logon?

Answer : declaring constant variables using if's and elsif's

Declare a public variable:

Public g_username As String

Then set the value in your function:
Public Function Startup()

If CurrentUser = "sgrafl01"
    g_username = "Sean Graflund"
Elseif CurrentUser = "dmarti01"
    g_username = "Donald Martin"
ElseIf .... and so on

End if
End Function

P.S. You may find it easier and more maintainable to put these values in a table.
Random Solutions  
 
programming4us programming4us