Advertisement
sergrv

Public Function OpenMyRecordset

Mar 30th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Function OpenMyRecordset(rs As ADODB.Recordset, strSQL As String, Optional rrCursor As rrCursorType, Optional rrLock As rrLockType, Optional bolClientSide As Boolean) As ADODB.Recordset
  2. On Error GoTo ErrorHandler
  3.    
  4.    
  5.     If con.State = adStateClosed Then
  6.        
  7.         con.ConnectionString = connection_str
  8.         'con.ConnectionString = "DRIVER={MySQL ODBC 5.3 Unicode Driver};" _
  9.         & "SERVER=server_ip;" _
  10.         & " DATABASE=db_name;" _
  11.         & "UID=user;PWD=password;" _
  12.         & "sslca=c:\server-ca.pem;" _
  13.         & "sslcert=c:\client-cert.pem;" _
  14.         & "sslkey=c:\client-key.pem;" _
  15.         & "OPTION=3;"
  16.     '  & "sslverify=1;" _
  17.  
  18.        con.Open
  19.     End If
  20.    
  21.     Set rs = New ADODB.Recordset
  22.     With rs
  23.         .ActiveConnection = con
  24.         If bolClientSide Then
  25.             .CursorLocation = adUseClient
  26.         Else
  27.             .CursorLocation = adUseServer
  28.         End If
  29.         .CursorType = IIf((rrCursor = 0), adOpenStatic, rrCursor)
  30.         .LockType = IIf((rrLock = 0), adLockReadOnly, rrLock)
  31.         .Open strSQL
  32.         If .EOF And .BOF Then
  33.             NoRecords = True
  34.             Exit Function
  35.         Else
  36.             NoRecords = False
  37.         End If
  38.     End With
  39.    
  40. ExitProcedure:
  41.     Exit Function
  42.  
  43. ErrorHandler:
  44.     Debug.Print Err.Description
  45.    
  46.     If Not rs Is Nothing Then
  47.         If (rs.State And adStateOpen) = adStateOpen Then
  48.             rs.Close
  49.         End If
  50.         Set rs = Nothing
  51.     End If
  52.    
  53.     If Not con Is Nothing Then
  54.         If (con.State And adStateOpen) = adStateOpen Then
  55.             con.Close
  56.         End If
  57.         Set con = Nothing
  58.     End If
  59.     NoRecords = True
  60.    
  61.     'MsgBox Err.Description, vbCritical, "Error:" & Err.number
  62.    GoTo ExitProcedure
  63.    
  64.    
  65. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement