I'm trying to create a recordset with a simple SQL statement. I am then going to use the records in the recordset to do an IF Then statement to change the Enabled property for a control on the open form.
I can't figure out why I keep getting no results from the SQL statement. I keep getting a "=nothing" and/or "out of context". Not sure if the .Value = "Yes" is right (Yes/No chkbx). maybe should be "-1" instead, but... I can't even get that far because the SQL is not querying the table. (Which I can do from the Navigation Pane with a query, no problem)
Thanks for any help.
Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strAdmin As String
Dim strPM As String
Dim strLM As String
Dim strRO As String
strSQL = "SELECT UserS3.UserID, UserS3.Administrator, UserS3.[Project Manager], UserS3.[Launch Manager], UserS3.[Read Only] FROM UserS3 WHERE (((UserS3.UserID)=GetLogonName()));"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
rst.MoveFirst
strAdmin = rst![Administrator]
strPM = rst![Project Manager]
strLM = rst![Launch Manager]
strRO = rst![Read Only]
If rst.Fields(strAdmin).Value = "Yes" Then Me.cmdOpenProgMgmt.Enabled = True Else: Me.cmdOpenProgMgmt.Enabled = False
rst.Close
End Sub
I can't figure out why I keep getting no results from the SQL statement. I keep getting a "=nothing" and/or "out of context". Not sure if the .Value = "Yes" is right (Yes/No chkbx). maybe should be "-1" instead, but... I can't even get that far because the SQL is not querying the table. (Which I can do from the Navigation Pane with a query, no problem)
Thanks for any help.
Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strAdmin As String
Dim strPM As String
Dim strLM As String
Dim strRO As String
strSQL = "SELECT UserS3.UserID, UserS3.Administrator, UserS3.[Project Manager], UserS3.[Launch Manager], UserS3.[Read Only] FROM UserS3 WHERE (((UserS3.UserID)=GetLogonName()));"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
rst.MoveFirst
strAdmin = rst![Administrator]
strPM = rst![Project Manager]
strLM = rst![Launch Manager]
strRO = rst![Read Only]
If rst.Fields(strAdmin).Value = "Yes" Then Me.cmdOpenProgMgmt.Enabled = True Else: Me.cmdOpenProgMgmt.Enabled = False
rst.Close
End Sub