X
XP
I have the following function which uses JET to return a disconnected
recordset; this runs great.
I just need to tweak this function to work with a password protected (i.e. a
database password) Access DB file, can someone show me how best to accomplish
this:
Public Function ADOReturnDisconnectedRecordsetJET(argFullNameDB As String,
argSQL As String) As ADODB.Recordset
'RETURNS A DISCONNECTED ADO RECORDSET TO THE CALLING SUBROUTINE OR FUNCTION
Dim cnAccess As ADODB.Connection
Dim rsAccess As ADODB.Recordset
Set cnAccess = New ADODB.Connection
cnAccess.Provider = "Microsoft.Jet.OLEDB.4.0"
cnAccess.ConnectionString = argFullNameDB
cnAccess.CursorLocation = adUseClient
cnAccess.CommandTimeout = 0 'NO TIMEOUT
cnAccess.Open
Set rsAccess = New ADODB.Recordset
rsAccess.MaxRecords = 0 '0 = ALL RECORDS
Set rsAccess = cnAccess.Execute(argSQL)
Set rsAccess.ActiveConnection = Nothing 'SEVER CONNECTION
Set ADOReturnDisconnectedRecordsetJET = rsAccess.Clone(adLockReadOnly)
'RETURN CLONE
If rsAccess.State = adStateOpen Then rsAccess.Close
Set rsAccess = Nothing
cnAccess.Close
Set cnAccess = Nothing
End Function
Thanks much.
recordset; this runs great.
I just need to tweak this function to work with a password protected (i.e. a
database password) Access DB file, can someone show me how best to accomplish
this:
Public Function ADOReturnDisconnectedRecordsetJET(argFullNameDB As String,
argSQL As String) As ADODB.Recordset
'RETURNS A DISCONNECTED ADO RECORDSET TO THE CALLING SUBROUTINE OR FUNCTION
Dim cnAccess As ADODB.Connection
Dim rsAccess As ADODB.Recordset
Set cnAccess = New ADODB.Connection
cnAccess.Provider = "Microsoft.Jet.OLEDB.4.0"
cnAccess.ConnectionString = argFullNameDB
cnAccess.CursorLocation = adUseClient
cnAccess.CommandTimeout = 0 'NO TIMEOUT
cnAccess.Open
Set rsAccess = New ADODB.Recordset
rsAccess.MaxRecords = 0 '0 = ALL RECORDS
Set rsAccess = cnAccess.Execute(argSQL)
Set rsAccess.ActiveConnection = Nothing 'SEVER CONNECTION
Set ADOReturnDisconnectedRecordsetJET = rsAccess.Clone(adLockReadOnly)
'RETURN CLONE
If rsAccess.State = adStateOpen Then rsAccess.Close
Set rsAccess = Nothing
cnAccess.Close
Set cnAccess = Nothing
End Function
Thanks much.