I have been working on a simple VBA function to check what type of User the current user is and opening the appropriate form for them at startup of my Access db. I have already defined a GetWindowsUserName function to get the username correctly as seen when I do Debug.Print, I used the following code:
Public Function CheckUser()
Dim UserName As String
Dim SQLType As String
UserName = UserNameWindows()
SQLType = "SELECT tbl_Users.[UserType] FROM tbl_Users WHERE tbl_Users.[SOEID]='" & UserName & "';"
Debug.Print SQLType
DoCmd.RunSQL SQLType
If SQLType = "Admin" Then
DoCmd.OpenForm "frm_AdminLandingPage"
DoCmd.Close acForm, "frm_Loading"
Else
DoCmd.OpenForm "frm_LandingPage"
DoCmd.Close acForm, "frm_Loading"
End If
End Function
Debug.Print results in the following for the SQL Statement, I also ran it in Access's SQL View and it runs just fine:
SELECT tbl_Users.[UserType] FROM tbl_Users WHERE tbl_Users.[SOEID]='GS429';
When I try to run the function however, it results in your typical "A RunSQL action requires an argument consisting of an SQL statement."
Thoughts? Thanks again for your help!
RunSQLis not forselectqueries. See this: stackoverflow.com/questions/27421873/…