I am trying to check what type of authorization a user has (which I get from my database) and then based on their
authorization I will make a certain button either visible or not.
However when I am trying to check the database I get the error:
Run-time error '-2417467259(80004005)':
Method 'Open' of object '_Recordset' failed
I don't know what I am doing wrong. I have pasted my code below. Any help would be greatly appreciated.
Sub Authorize()
Dim stSQL As String
Dim tester As Outlook.Application
Dim UserName As String
Dim User As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.Open stdbName
Set tester = ThisOutlookSession
UserName = tester.Session.CurrentUser.Name
stSQL = "SELECT authorization FROM UserDataTable WHERE name = '" & UserName & "'"
rs.Open stSQL, cn
If rs("authorization") = 0 Then
UserForm6.CommandButton1.Visible = True
Else
UserForm6.CommandButton1.Visible = False
End If
rs.Close
End Sub
-joker16
authorization I will make a certain button either visible or not.
However when I am trying to check the database I get the error:
Run-time error '-2417467259(80004005)':
Method 'Open' of object '_Recordset' failed
I don't know what I am doing wrong. I have pasted my code below. Any help would be greatly appreciated.
Sub Authorize()
Dim stSQL As String
Dim tester As Outlook.Application
Dim UserName As String
Dim User As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.Open stdbName
Set tester = ThisOutlookSession
UserName = tester.Session.CurrentUser.Name
stSQL = "SELECT authorization FROM UserDataTable WHERE name = '" & UserName & "'"
rs.Open stSQL, cn
If rs("authorization") = 0 Then
UserForm6.CommandButton1.Visible = True
Else
UserForm6.CommandButton1.Visible = False
End If
rs.Close
End Sub
-joker16