Insert data from from to different table in VBA

lousy

New member
Local time
Today, 08:06
Joined
Jun 11, 2011
Messages
3
I am trying to insert data from a form to antother table in VBA and would like to do this without using a macro. I have got the following code but it doesn't work. Can anyone help me????

Dim appointmentdate As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strsql As String
Set db = CurrentDb()

Set rst = db.OpenRecordset("tbl date", dbOpenDynaset)
appointmentdate = Me.Appointment_Date

Set rst = db.OpenRecordset("INSERT INTO tbldate ( appointmentdate) VALUES (" & appointmentdate & ")")
 
You have not given us much to go on but a recordset canot be opend on an INSERT query

Use the Execute Method to insert the value from the form to the table.

Dates in SQL strings also need to be in mm/dd/yyy format and properly delimited.

Code:
db.Execute "INSERT INTO tbldate (appointmentdate) VALUES (" & Format(appointmentdate, "\#mm\/dd\/yyyy\#") & ")"
 
Sorry

I am trying to take the appointment date from my existing form and put put it in another table. I can do it with a macro but after awhile this is going to become very slow and I thought in VBA it would be quicker to process.

Dim dbData As DAO.Database


Set dbData = CurrentDb()
dbData.Execute ("INSERT INTO tbl_date (appointment_date) VALUES (" & Format(Appointment_Date, "\#mm\/dd\/yyyy\# "))
 

Users who are viewing this thread

Back
Top Bottom