PDA

View Full Version : Appending Records to Access Table using VBA defined variables



stuplumley
10-31-2006, 09:11 AM
Hi, this is my second day of using VBA and I have this, hopefully simple, problem.

I want to update an Access table with results of code run against a Recordset (I have scanned the recordset for the date of incident 1, the date of incident 2 and calculated the difference).

I know want to put these 3 values (inc1Date, incDate and incDiff) into an Access table [Results], set up with 3 fields (([Date 1[Date 2], [Difference]), and then append the results of similar Recordset queries.

This doesnt work

DoCmd.RunSQL "insert into[Results] ([Date 1[Date 2], [Difference]) values (inc1Date, incDate , incDiff)"

What am I missing? The 3 variable all have valid values, which I've checked in my code, but the "append" query doesnt recognise their names. Am I missing !s or square brackets somewhere?

Thanks

Norie
10-31-2006, 10:39 AM
Do you really need to do this using VBA?

Couldn't you just use a query to get the required result?

If you really want to do it I suggest you create the query using the query builder.

Once you get it working correctly goto View>SQL to see the correct SQL, which you can then copy into your code.

stanl
10-31-2006, 12:41 PM
Unless there was a typo in your original post



DoCmd.RunSQL "insert into[Results] ([Date 1[Date 2], [Difference]) values (inc1Date, incDate , incDiff)"


you might try



DoCmd.RunSQL "insert into [Results] ([Date 1], [Date 2], [Difference]) values (inc1Date, incDate , incDiff);"


.02 Stan