Select Into - Insert Into - Problem

  • Thread starter Thread starter jack
  • Start date Start date
J

jack

Hi,
I'm trying to use either of the following from a form, but
alas neither work

DoCmd.RunSQL "SELECT Timesheet.* into DBID FROM Timesheet;"

DoCmd.RunSQL "Insert into timesheet in DBID select * from
timesheet"

where DBID equals DBID = "C:\CHLOE\CompletedJobs\" & Me!
txtJobNumber & "-" & Me!txtExtension & ".mdb;"

Would it be possisibl;e for someone to please explain why
is it so??
Thanks
 
jack said:
Hi,
I'm trying to use either of the following from a form, but
alas neither work

DoCmd.RunSQL "SELECT Timesheet.* into DBID FROM Timesheet;"

DoCmd.RunSQL "Insert into timesheet in DBID select * from
timesheet"

where DBID equals DBID = "C:\CHLOE\CompletedJobs\" & Me!
txtJobNumber & "-" & Me!txtExtension & ".mdb;"

Would it be possisibl;e for someone to please explain why
is it so??
Thanks

First, if DBID is a variable, then you'd have to concatenate its value
into the the SQL string:

Dim strSQL As String

strSQL = "SELECT Timesheet.* INTO " & DBID & " FROM Timesheet;"

DoCmd.RunSQL

But that won't work as is, because the value of DBID doesn't include a
table specification. You're close with your second attempt. Try this:

Dim strSQL As String

strSQL = _
"INSERT INTO Timesheet IN '" & _
DBID & "' SELECT * FROM Timesheet;"

DoCmd.RunSQL
 
Back
Top