when I step through my VBA code - when it opens the connection string - it creates another file (type of file: Microsoft Access Record-Locking Information (.laccdb)) and once the this code is finished - it closes that file
here is my full code to update this log database which is not protected - my aim is to protect it so no one else can phycally manually open it without knowing the password - thanks
Code:
Sub ExportDataToAccess()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strQuery As String
Dim LogDate As Date
Dim LogTime As Date
Dim myDB As String
Application.ScreenUpdating = False
'Initialize Variables
LogDate = Date
LogTime = Format(Now(), "hh:mm:ss")
UserId = Environ("username")
'myDB = "replace with the fully qualified path to your Access Db"
myDB = "C:\Users\my.DESKTOP-8BKSK49\Desktop\Access Log Files\LogDatabase.accdb"
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0" 'For *.ACCDB Databases
.ConnectionString = myDB
.Open
End With
On Error GoTo CloseConnection
With rs
.ActiveConnection = cn
.Source = "LogTable"
.LockType = adLockOptimistic
.CursorType = adOpenForwardOnly
.Open
On Error GoTo CloseRecordset
.AddNew
.Fields("Log_Date").Value = LogDate
.Fields("Log_Time").Value = LogTime
.Fields("UserID").Value = UserId
.Update
End With
CloseRecordset:
rs.Close
CloseConnection:
cn.Close
Set rs = Nothing
Set cn = Nothing
Application.ScreenUpdating = True
End Sub