Results 1 to 3 of 3
  1. #1
    Ormusia is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    1

    Question Same query, different results?

    First post.

    I have been assigned an Access project.
    It's fun, yet challenging when inexperienced.



    When you first open the db, specifically the main form, the code detects the absence of two tables, xps and mps. (Images below).
    It then creates these tables by importing from two spreadsheets...

    Code:
    DoCmd.TransferSpreadsheet acImport, , "mps", mps, True
    DoCmd.TransferSpreadsheet acImport, , "xps", xps, True
    Once that is done, the user will press a button to insert into a third table a collation of fields from the two created tables based on a field they share and how old is the entry, using this code:

    Code:
    Private Sub MagicButton_Click()
        Dim db As Database
        Dim sql As String
        Dim sDate As Date
        sDate = DateAdd("m", -2, Date)
        
        sql = "INSERT INTO res " & _
                "(" & _
                   "[Asset Number], " & _
                   "[Market Centre]," & _
                   "[Partner or XPS Account Name], " & _
                   "[Account Name], " & _
                   "[Serial Number]," & _
                   "[3rd Party Manufacturing Serial Number]," & _
                   "[Offering], " & _
                   "[Price Plan], " & _
                   "[Last Bill Date]," & _
                   "[Current Read Date]" & _
                ") "
                
        sql = sql & "SELECT DISTINCT " & _
                   "mps.[Asset Number], " & _
                   "mps.[Responsibility Name], " & _
                   "xps.[Partner or XPS Account Name], " & _
                   "xps.[Account Name], " & _
                   "xps.[Serial Number], " & _
                   "xps.[3rd Party Manufacturing Serial Number], " & _
                   "xps.[Offering], " & _
                   "xps.[Price Plan], " & _
                   "xps.[Last Bill Date], " & _
                   "xps.[Current Read Date] "
                   
         sql = sql & "FROM xps INNER JOIN mps " & _
                   "ON xps.[Serial Number] = mps.[Asset Number] " & _
                   "WHERE xps.[Last Bill Date] = #12/30/1899# Or xps.[Last Bill Date] < " & "#" & sDate & "#" & " ORDER BY mps.[Responsibility Name];"
                   
        Debug.Print sql
        
        Set db = CurrentDb
        db.Execute sql, dbFailOnError
    End Sub
    So, after some time, I got this INSERT INTO statement to work.
    Worth noting that this was done through many cycles of creation and destruction and creation of those two tables via spreadsheet imports.
    Every time you close the form it deletes the tables and when you open the form recreates them based on the transferspreadsheet call.

    So, it was working.
    I had done it!

    So I copied the db, opened it, manually deleted the two tables, and ran the form again.
    This time the tables got reimported, and then, when I pressed the magic button to do the INSERT INTO...

    It Failed!
    Same code, yet it failed. It also never worked after I had manually deleted the tables.

    So I opened the original on one side, the copy on the other side.
    Same code, same tables, same field names and types, same bloody everything.
    Did not manually delete the tables: works.
    Did manually delete the tables: fails forever after.

    This, well, this melts my mind.

    The error it gives is one I had wrestled against before: 3061 Too few parameters, Expected 1.

    Here's the error, and the tables for both the copy (not working after tables recreations) and the original (works unless I recreate the tables)

    Click image for larger version. 

Name:	error 3061.PNG 
Views:	8 
Size:	52.0 KB 
ID:	21002Click image for larger version. 

Name:	res.PNG 
Views:	8 
Size:	45.7 KB 
ID:	21003Click image for larger version. 

Name:	mps.PNG 
Views:	8 
Size:	63.4 KB 
ID:	21004Click image for larger version. 

Name:	xps.PNG 
Views:	8 
Size:	37.5 KB 
ID:	21005


    Any advice would be greatly appreciated.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe the issue is Responsibility Name and Market Centre not matching. It is past my bed time but that is what jumped out at me.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I don't know why manually deleting tables would cause code to fail but try running Compact & Repair after manual delete before running code.

    Why create and delete tables? This causes design modification which is not advisable as a routine process. Maybe better to delete records then import into existing tables.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 7
    Last Post: 05-27-2015, 12:45 PM
  2. Replies: 5
    Last Post: 05-21-2013, 02:21 PM
  3. Replies: 3
    Last Post: 05-02-2013, 10:36 AM
  4. Replies: 2
    Last Post: 03-25-2013, 09:10 AM
  5. Replies: 6
    Last Post: 05-14-2012, 07:24 AM

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