Hi,lucausa75
Thank you for consulting Microsoft Community.
To connect to an encrypted SQLite database using Excel VBA, you need to include the encryption password in your connection string. Since you used SQLCipher for encryption, your connection string should include the Password parameter. Here’s how you can modify your existing code:
Private Sub cmdConnect_Click()
Dim Conn As ADODB.Connection
Dim Rst As ADODB.Recordset
Dim Conn_String As String
Dim Database_path As String
Dim SQL_statement As String
Dim i As Long
Database_path = "D:\FOLDER\Development\SQLlite_VBA\DB_SQLite"
Conn_String = "driver=SQLite3 ODBC Driver;"
Conn_String = Conn_String & "Database=" & Database_path & ";"
Conn_String = Conn_String & "Password=your_password;" ' Add your password here
Set Conn = New ADODB.Connection
With Conn
.Open Conn_String
.CursorLocation = adUseClient
End With
SQL_statement = "SELECT * FROM 'Export_Table'"
Set Rst = New ADODB.Recordset
With Rst
.CursorLocation = adUseClient
.Open Source:=SQL_statement, ActiveConnection:=Conn
End With
With ThisWorkbook.Worksheets("Export")
.Cells.ClearContents
.Range("A2").CopyFromRecordset Rst
For i = 0 To Rst.Fields.Count - 1
.Cells(1, i + 1) = Rst.Fields(i).Name
Next i
End With
Rst.Close
Conn.Close
Set Rst = Nothing
Set Conn = Nothing
ThisWorkbook.Worksheets("Export").Range("A2").Select
End Sub
Replace your_password with the actual password you set for your SQLite database.
If you encounter any issues, make sure that the ODBC driver you are using supports encrypted SQLite databases. You might need to check the documentation for the specific driver you are using to ensure it supports the Password parameter.
We look forward to your feedback on the results of the operation, if you need further assistance, please feel free to reply.
Cherry.Z|Microsoft Technical Support Specialist