Results 1 to 6 of 6
  1. #1
    dccjr3927 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    130

    Runtime 3078 While Using INSERT from a Recordset

    Good Evening:

    I have been in non-VBA mode for the past year, and cannot seem to see thing that are probably obvious to others. I am getting a Runtime 3078 (cannot find the input table or query "INSERT INTO...") Below is the sub. I would really appreciate it if someone could lend a second pair of eyes. I have double checked that table and field names are correct.

    Code:
    Private Sub cmdLogVol_Click()
        Dim strInsertSQL, strQuerySQL As String
        Dim dteVolDate As Date
        Dim db As DAO.Database
        Dim rsInsert As Recordset
        dteVolDate = Format(Date, "Short Date")
        Set db = CurrentDb
        strQuerySQL = "SELECT Company, SKU, InvVolume FROM Inventory WHERE Company = 'Contract - Company1' OR Company = 'Contract - Company2';"
        Set rsInsert = db.OpenRecordset(strQuerySQL)
        strInsertSQL = "'INSERT INTO InvVolData (Company, SKU, InvVolume, VolDate) VALUES (' & rs!Company & ',' & rs!SKU & ',' & rs!InvVolume & ',' & dteVolDate & ';'"
        db.Execute strInsertSQL, dbFailOnError
    End Sub
    Thanks in advance for any insight.
    Last edited by dccjr3927; 02-08-2021 at 10:24 AM.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Instead of SQL,use a query.
    it won't get the syntax wrong. Then just run it: docmd.openquery "qaInsertQry"

  3. #3
    dccjr3927 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    130
    Hi ranman256:

    Not really sure what you mean. Do you mean build a query with the query builder/wizard? To be perfectly honest, I have never built a query that way.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    you are missing a closing bracket in your VALUES part

    you are also missing double quotes between each rs! value

    suggest put debug.print strInsertSQL after you have created it to see what it actually looks like before you execute it

    dates need to be in the format mm/dd/yyyy and surrounded with the # character

    not clear what your data types are but text needs to be surrounded with single quotes, numbers do not

    other issues - you are not checking that rs is populated - perhaps there are no records that meet that criteria?

  5. #5
    dccjr3927 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    130
    Thank you very much. With your changes, it works perfectly.

    Here is the corrected code for others reference:

    Code:
    Private Sub cmdLogVol_Click()
        Dim strInsertSQL, strQuerySQL As String
        Dim dteVolDate As Date
        Dim db As DAO.Database
        Dim rsInsert As Recordset
        
        dteVolDate = Format(Date, "Short Date")
        Set db = CurrentDb
        strQuerySQL = "SELECT Company, SKU, InvVolume FROM Inventory WHERE Company = 'Contract - Company1' OR Company = 'Contract - Company2';"
        Set rsInsert = db.OpenRecordset(strQuerySQL)
        
        If Not rsInsert.EOF Then
            Do Until rsInsert.EOF
            strInsertSQL = "INSERT INTO InvVolData (Company, SKU, InvVolume, VolDate) VALUES ('" & rsInsert!Company & "','" & rsInsert!SKU & "'," & rsInsert!InvVolume & ",#" & dteVolDate & "#);"
            db.Execute strInsertSQL, dbFailOnError
            rsInsert.MoveNext
            Loop
        End If
        
    End Sub

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Wondering if you realize that strInsertSQL is a variant because you didn't specify a data type for it? That is

    Dim strInsertSQL As String, strQuerySQL As String
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. recordset Runtime Error 3075
    By DMT Dave in forum Access
    Replies: 2
    Last Post: 02-20-2019, 06:11 AM
  2. Insert records from one recordset into another
    By CanuckBuck in forum Programming
    Replies: 2
    Last Post: 01-19-2016, 01:33 PM
  3. insert getting runtime error 3134
    By vicsaccess in forum Programming
    Replies: 5
    Last Post: 12-06-2015, 09:50 PM
  4. Insert into table from recordset
    By Colargol in forum Programming
    Replies: 2
    Last Post: 12-10-2011, 06:43 PM
  5. Run Time Error 3078
    By jimjaix in forum Access
    Replies: 2
    Last Post: 02-02-2010, 12:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums