Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Object Required Error On Insert Into Statement

$
0
0
Hi all,

Using Access 2007.

Trying to write some VBA to append user-selected tables to comaprison tables.

My code is bombing here at db.Execute
Code:

'Previous month
    sSQL = ""
    sSQL = sSQL & "INSERT INTO tbl_PartsPrevious (PT, Part) "
    sSQL = sSQL & "SELECT " & sPTable & ".PT, " & sPTable & ".Part "
    sSQL = sSQL & "FROM " & sPTable & ";"
   
    Debug.Print sSQL
   
    db.Execute (sSQL)

I wrote an append query using the query designer. That SQL looks very much like the SQL above.

The table exists, the spelling is correct as are the names of the fields.
Here is the SQL string that Debug.Pring prints to the immediate window

Quote:

INSERT INTO tbl_PartsPrevious (PT, Part) SELECT tblParts1209.PT, tblParts1209.Part FROM tblParts1209;
Do you see anything wrong?
Thx
w

Full code:
Code:

Option Compare Database

Sub CompareMonths()

    'Environment
    DoCmd.SetWarnings False
   
    'Variables
    Dim sPTable As String
    Dim sCTable As String
    Dim sSQL As String
   
    'Clear comparison tables
    DoCmd.OpenQuery "qdel_tblPartsPrevious_Clear"
    DoCmd.OpenQuery "qdel_tblPartsCurrent_Clear"
   
    'Get selected table name
    sPTable = Forms!Parts!lstPMonth.Value 'Previous Month
    sCTable = Forms!Parts!lstCMonth.Value 'Current Month
   
    'Append selected tables to comparison tables
    strStatus = "Appending records..."
    varStatus = SysCmd(acSysCmdSetStatus, strStatus)
   
   
    'Previous month
    sSQL = ""
    sSQL = sSQL & "INSERT INTO tbl_PartsPrevious (PT, Part) "
    sSQL = sSQL & "SELECT " & sPTable & ".PT, " & sPTable & ".Part "
    sSQL = sSQL & "FROM " & sPTable & ";"
   
    Debug.Print sSQL
   
    db.Execute (sSQL)
   
    'Current month
    sSQL = ""
    sSQL = sSQL & "INSERT INTO tbl_PartsCurrent (PT, Part) "
    sSQL = sSQL & "SELECT " & sCTable & ".PT, " & sPTable & ".Part "
    sSQL = sSQL & "FROM " & sCTable & ";"
    db.Execute (sSQL)
 
 
    varStatus = SysCmd(acSysCmdClearStatus)

End Sub


Viewing all articles
Browse latest Browse all 13329

Trending Articles