Microsoft
Software
Hardware
Network
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
GetUserProfileByName Issue after form is submitted
2008 server & 2000 Professional client
Converting text to date
Normal.dot NOT set to read-only, but i cannot delete or rename it
Access Calendar Control Help
VBA - Combo Box ID
WHAT IS AN ILIST,IDATASOURCE,IENUMERA<wbr />BLE
Read matching files in a folder, read one of them and insert the Data in a Table
Is there a way to have excel notify you of a change made on a particular spreadsheet?
Unable to remove buritos.exe trojan from UPS email