K
Kerry Purdy
Hiya
I have been given 2 conflicting sets of advice about inserting data into a
table.
I have a table (tbl dummymatrixdata) which needs to be emptied (delete
query), then filled with a list of dates between the start and end dates
entered by the user.
I was advised to use ADO for inserting records and have also been advised to
use an append query. Which is best? I would realy appreciate some help witht
he current code, or if its the inserting records using ADO I don't have any
experience using this atall.
Thank you very much for your time.
Kerry
The code below is as far as I have got with using the SQL from an append
query. Up to the msgbox new day all works well, it shows the correct days in
the message box up to the end date.
Its the DoCmd.RunSql that shows an error of "Run time error 3134, syntax
error in INSERT INTO statement"
Sub DummyMatrix()
'xxx Pull dates from the Main Switchboard - fill variables xxx
RptStart = Forms![Frm Main SB]![StartDateEntry]
RptEnd = Forms![Frm Main SB]![EndDateEntry]
RptDur = DateDiff("d", RptStart, RptEnd)
'xxx Run delete query to empty all records from DummyMatrix Table xxx
DoCmd.OpenQuery ("qry DelMatrixDData")
'xxx Run loop to insert each date btwn RptStart & RptEnd into DummyMatrix
table xxx
For x = 0 To RptDur
NewDay = RptStart + x
'MsgBox NewDay
DoCmd.RunSQL "INSERT INTO tbl MatrixDummyData (MatrixDate) VALUES
(NewDay)"
Next x
End Sub
I have been given 2 conflicting sets of advice about inserting data into a
table.
I have a table (tbl dummymatrixdata) which needs to be emptied (delete
query), then filled with a list of dates between the start and end dates
entered by the user.
I was advised to use ADO for inserting records and have also been advised to
use an append query. Which is best? I would realy appreciate some help witht
he current code, or if its the inserting records using ADO I don't have any
experience using this atall.
Thank you very much for your time.
Kerry
The code below is as far as I have got with using the SQL from an append
query. Up to the msgbox new day all works well, it shows the correct days in
the message box up to the end date.
Its the DoCmd.RunSql that shows an error of "Run time error 3134, syntax
error in INSERT INTO statement"
Sub DummyMatrix()
'xxx Pull dates from the Main Switchboard - fill variables xxx
RptStart = Forms![Frm Main SB]![StartDateEntry]
RptEnd = Forms![Frm Main SB]![EndDateEntry]
RptDur = DateDiff("d", RptStart, RptEnd)
'xxx Run delete query to empty all records from DummyMatrix Table xxx
DoCmd.OpenQuery ("qry DelMatrixDData")
'xxx Run loop to insert each date btwn RptStart & RptEnd into DummyMatrix
table xxx
For x = 0 To RptDur
NewDay = RptStart + x
'MsgBox NewDay
DoCmd.RunSQL "INSERT INTO tbl MatrixDummyData (MatrixDate) VALUES
(NewDay)"
Next x
End Sub