【发布时间】:2015-10-30 14:49:12
【问题描述】:
我一直在研究一个简单的 VBA 函数来检查当前用户是什么类型的用户,并在我的 Access db 启动时为他们打开适当的表单。我已经定义了一个 GetWindowsUserName 函数来正确获取用户名,正如我在执行 Debug.Print 时看到的那样,我使用了以下代码:
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 的 SQL 语句结果如下,我也在 Access 的 SQL 视图中运行它,它运行得很好:
SELECT tbl_Users.[UserType] FROM tbl_Users WHERE tbl_Users.[SOEID]='GS429';
但是,当我尝试运行该函数时,它会导致典型的“RunSQL 操作需要一个由 SQL 语句组成的参数。”
想法?再次感谢您的帮助!
【问题讨论】:
-
不幸的是同样的错误。 :(
-
RunSQL不适用于select查询。看到这个:stackoverflow.com/questions/27421873/…