Hi,
I'm getting error in the below code. I think i have the INSERT statement wrong.
can anyone help? thank you
i have thins on e
I'm getting error in the below code. I think i have the INSERT statement wrong.
can anyone help? thank you
i have thins on e
VBA Code:
Private Sub Workbook_Open()
Dim data As Date
Dim user As String
Dim ficheiro As String
'Creating objects of Connection and Recordset
Dim conn As New Connection, rec As New Recordset
Dim DBPATH, PRVD, connString, query As String
'Declaring fully qualified name of database. Change it with your database's location and name.
DBPATH = "C:\Users\xrada76\Documents\RegistoDb.accdb"
'This is the connection provider. Remember this for your interview.
PRVD = "Microsoft.ace.OLEDB.12.0;"
'This is the connection string that you will require when opening the the connection.
connString = "Provider=" & PRVD & "Data Source=" & DBPATH
'opening the connection
conn.Open connString
data = Now
user = Application.UserName
ficheiro = ThisWorkbook.Name
'the query I want to run on the database.
query = " INSERT INTO RegistosDb (Data, User, NomeFicheiro) VALUES ('" & data & "', '" & user & "', '" & ficheiro & "') "
'running the query on the open connection. It will get all the data in the rec object.
rec.Open query, conn
'closing the connections
rec.Close
conn.Close
End Sub