Error on closing a ADODB.Recordset VBA

Anonymous
2022-12-10T08:33:15+00:00

Dear all,

I have built this VBA function but I'm getting the below error (see the next screenshot) in the bold portion of the code:

Public Sub UserLogoutDetail(UserEmail As String) 

    Dim MySQL As String 

    Dim RstUserAccess As New ADODB.Recordset 

    Dim CmdUserAccess  As New ADODB.Command 

    Dim i As Integer 

    'Setup the command 

    Set CmdUserAccess.ActiveConnection = fGetConn 

    CmdUserAccess.CommandType = adCmdText 

    MySQL = "UPDATE User_Access_TABLE SET EXIT_DATA = #" & Now & "# WHERE (((ID)=" & GetID_ToUpdate(UserEmail) & "))" 

    CmdUserAccess.CommandText = MySQL 

    RstUserAccess.CursorLocation = adUseClient 

    RstUserAccess.CursorType = adOpenDynamic 

    RstUserAccess.LockType = adLockOptimistic 

    'Open the connection 

    RstUserAccess.Open CmdUserAccess 

Set RstUserAccess.ActiveConnection = Nothing 

RstUserAccess.Close

    'Cleanup 

    If CBool(CmdUserAccess.State And adStateOpen) = True Then 

        Set CmdUserAccess = Nothing 

    End If 

    If CBool(fGetConn.State And adStateOpen) = True Then 

        CloseConn 

    End If 

 End Sub

Do you have any suggestion?

Thanks

Microsoft 365 and Office | Excel | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. Anonymous
    2022-12-10T15:37:27+00:00

    ...done but I don't understand the error:

    0 comments No comments
  2. HansV 462.4K Reputation points MVP Volunteer Moderator
    2022-12-10T15:58:01+00:00

    Remove that line too.

    Why don't you follow my suggestion to do away with the recordset and use the Execute method of the Command object?

    0 comments No comments