Page 2 of 2 FirstFirst 12
Results 16 to 29 of 29
  1. #16
    Marianna_Air is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    56
    Click image for larger version. 

Name:	data_model.jpg 
Views:	19 
Size:	74.7 KB 
ID:	9111
    It might be the location of the button, its on the Parent form
    The Error is a Compile, method or data member not found

  2. #17
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I apologize, Marianna_Air! I completely missed the part about duplicating a Record from the Main Form and related Records from a SubForm, and the posted code will not work, for that!

    I have never needed to do this and therefor have no experience with it. I've seen hacks around, for this task, but never had enough interest to even archive any of them. I will look around and see if I can find one for you.

    Just for the record, are we talking about a Main Form Record and one Record from the Subform, or Multiple Records from the Subform?

    Linq ;0)>

  3. #18
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I think we were on the right track before "You're really over-engineering this thing". You might start again at that point.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #19
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I've been out. Just came back to notice the form, subform was a real situation as suspected after your earlier post.

    I think Paul is right --there's probably an easier way to do what you want.

  5. #20
    Marianna_Air is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    56
    I agree, this beast is growing, I just keep adding to it to fix one problem and a new one pops up. I'm too much of a novice!!! urggggg
    This is where I ended up previously. I'm getting an error of "too few parameters. Expected 2." and debug highlites the code in red below


    Code:
    Private Sub Command169_Click()
    'On Error GoTo Err_Handler
        'Purpose:   Duplicate the main form record and related records in the subform.
        Dim strSql As String    'SQL statement.
        Dim strID As String      'Primary key value of the new record.
        
        'Save any edits first
        If Me.Dirty Then
            Me.Dirty = False
        End If
        
        'Make sure there is a record to duplicate.
        If Me.NewRecord Then
            MsgBox "Select the record to duplicate."
        Else
            'Duplicate the main record: add to form's clone.
            With Me.RecordsetClone
                .AddNew
                    !EmployeeID = Me.EmployeeID
                    !RequestDate = Date
                    !RequestforQuotesID = GetNextSN("RFQ")
                    'etc for other fields.
                .Update
                
                'Save the primary key value, to use as the foreign key for the related records.
                .Bookmark = .LastModified
               strID = !RequestforQuotesID
                
                'Duplicate the related records: append query.
                If Me.[Request for Quotes Subform].Form.RecordsetClone.RecordCount > 0 Then
                    strSql = "INSERT INTO [Inventory Transactions] (RequestforquotesID, ProductID, UnitsOrderedConv) " & _
                        "SELECT " & strID & " As requestforquotesID, ProductID, UnitsOrderedConv " & _
                        "FROM [Inventory Transactions] WHERE requestforquotesID = " & Me.RequestforQuotesID & ";"
                    DBEngine(0)(0).Execute strSql, dbFailOnError
              Else
                    MsgBox "Main record duplicated, but there were no related records."
                End If
                
                'Display the new duplicate.
                Me.Bookmark = .LastModified
            End With
        End If
    Exit_Handler:
        Exit Sub
    Err_Handler:
        MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdDupe_Click"
        Resume Exit_Handler
    End Sub

  6. #21
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Yes, and right after you posted that before I posted a method (post 8) to help us debug:

    http://www.baldyweb.com/ImmediateWindow.htm

    And said "Offhand, I suspect you need to surround that value in single quotes since it's text not numeric (in both places)."
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #22
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by pbaldy View Post
    I think we were on the right track before "You're really over-engineering this thing".
    I agree, and wouldn't have said that if I realized that we were talking about duplicating Form and Subform Records! I probably should stay off-line until my daughter's wedding is over with! Way too much multi-tasking for a man well into his sixth decade on the planet!

    Linq ;0)>

  8. #23
    Marianna_Air is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    56
    I ran my code on a record that has no sub records and it worked. It even gave me the massage that the "Main Record was Duplicated, but there were no related records" so it seems to work up to that point, but as soon as I try to duplicate a record that has related records(sub records) I get the error of "too few parameters. Expected 2." and it points to the same issue I previously highlighted "DBEngine(0)(0).Execute strSql, dbFailOnError"

  9. #24
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    You don't have to use this specific statement/syntax
    "DBEngine(0)(0).Execute strSql, dbFailOnError"

    For an action query Insert/Update/Delete you could use

    yourDatabasereference.Execute yourActionQuerySQL,dbFailOnError

    could be Currentdb.execute strSQL,dbFailOnError
    also as Paul has been mentioned, you could have a
    Debug.Print strSQL before the ...execute statement to write the "rendered SQL" to the immediate window.


    The "too few parameters...." can signal spelling errors in some cases.

    The debug.print should show us the rendered SQL.

    I think your Me.subform.... is incorrect syntax.

    Form subform reference can be found at
    http://access.mvps.org/access/forms/frm0031.htm
    Last edited by orange; 09-12-2012 at 09:07 AM. Reason: highlighting Paul's debug comment

  10. #25
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Quote Originally Posted by Marianna_Air View Post
    I ran my code on a record that has no sub records and it worked. It even gave me the massage that the "Main Record was Duplicated, but there were no related records" so it seems to work up to that point, but as soon as I try to duplicate a record that has related records(sub records) I get the error of "too few parameters. Expected 2." and it points to the same issue I previously highlighted "DBEngine(0)(0).Execute strSql, dbFailOnError"
    Are posts 8 and 21 not showing up on your PC?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #26
    Marianna_Air is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    56
    I wonder if I can make this work for me, http://support.microsoft.com/kb/208824
    Any thoughts?

    I'm giving up on what I have I've tried everything "debug.print" and everything else, I just can't figure it out. I think it's time to start over fresh, maybe give what the link above shows a try if ya'll think it might work?

  12. #27
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You say you've tried the debug.print, but you haven't posted the SQL here, nor addressed whether you've added the quotes I mentioned.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #28
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  14. #29
    Marianna_Air is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    56
    Sorry I went in another direction already so I can't show you that info Orange, Pbaldy I apologize.

    I've made some headway with this problem but alas I'm up against a wall again. I've come up with a way to get the records from the Form and subform to duplicate and they show in their individual tables, but I can't seem to figure out 2 things 1:how to get them to show on the newly created form/subform, and 2: I have not been able to figure out how to give the new record a new ID like"RFQ1234" I'm going to paste both the VBA code and SQL

    Code:
    Private Sub btnDuplicate_Click()
    Dim dbs As DAO.Database, Rst As DAO.Recordset
    Dim F As Form
    ' Return Database variable pointing to current database.
    Set dbs = CurrentDb
    Set Rst = Me.RecordsetClone
    On Error GoTo Err_btnDuplicate_Click
    ' Tag property to be used later by the append query.
    Me.Tag = Me![RequestforQuotesID]
    ' Add new record to end of Recordset object.
    With Rst
       .AddNew
          !EmployeeID = Me!EmployeeID
          !Originator = Me!Originator
       .Update                     ' Save changes.
       .Move 0, .LastModified
    End With
    Me.Bookmark = Rst.Bookmark
    ' Run the Duplicate Order Details append query which selects all
    ' detail records that have the OrderID stored in the form's
    ' Tag property and appends them back to the detail table with
    ' the OrderID of the duplicated main form record.
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "Duplicate Request For Quotes Details"
    DoCmd.SetWarnings True
    'Requery the subform to display the newly appended records.
    Me![request for quotes subform].Requery
    Exit_btnduplicate_Click:
    Exit Sub
    Err_btnDuplicate_Click:
    MsgBox Error$
    Resume Exit_btnduplicate_Click:
    End Sub

    Code:
    
    INSERT INTO [Inventory Transactions] ( TransactionID, ProductID, TransactionDescription, TransferFromID, CustomerID, UnitPrice, UnitsOrdered, UnitsReceived, UnitsReceivedFG, UnitsSold, UnitsShipped, UnitsShippedFG, UnitsShrinkage, PPnumber, DateRequired, DatePromised, SerialNumber, SalesOrderID, ModelNumber, Control, ShippedDate, ShippingMethodID, ShippingTracking, SalesTracking, CustomerPO, Ordered, ETA, Delivered, [Userdefinable 1], [Userdefinable 2], [Userdefinable 3], [Currency], Levelnumber, PP, InvoiceNumber, InvoiceDate, Explode, delevel, accountID, DepartmentAutoID, OrderLine, PackingOrderID, ShipFromID, ShipToID, UnitsOfMeasure, [WOB/O], TaxRate, isExported, GLAccount, SalesUnitPriceConv, qbTaxCode, SalesDescription, qbExportedDate, ChosenCustomerID, ChosenShipToID, BOMAmount, UnitPriceConv, UnitsOrderedConv, UnitsShippedConv, UnitsShippedFGConv, UnitsReceivedConv, UnitsReceivedFGConv, Categories, ChosenTransferFromID, ChosenShipFromID, SourceTransactionID, LineAttributes, LineType, QtyPerParent, Cogs )
    SELECT [Inventory Transactions].TransactionID, [Inventory Transactions].ProductID, [Inventory Transactions].TransactionDescription, [Inventory Transactions].TransferFromID, [Inventory Transactions].CustomerID, [Inventory Transactions].UnitPrice, [Inventory Transactions].UnitsOrdered, [Inventory Transactions].UnitsReceived, [Inventory Transactions].UnitsReceivedFG, [Inventory Transactions].UnitsSold, [Inventory Transactions].UnitsShipped, [Inventory Transactions].UnitsShippedFG, [Inventory Transactions].UnitsShrinkage, [Inventory Transactions].PPnumber, [Inventory Transactions].DateRequired, [Inventory Transactions].DatePromised, [Inventory Transactions].SerialNumber, [Inventory Transactions].SalesOrderID, [Inventory Transactions].ModelNumber, [Inventory Transactions].Control, [Inventory Transactions].ShippedDate, [Inventory Transactions].ShippingMethodID, [Inventory Transactions].ShippingTracking, [Inventory Transactions].SalesTracking, [Inventory Transactions].CustomerPO, [Inventory Transactions].Ordered, [Inventory Transactions].ETA, [Inventory Transactions].Delivered, [Inventory Transactions].[Userdefinable 1], [Inventory Transactions].[Userdefinable 2], [Inventory Transactions].[Userdefinable 3], [Inventory Transactions].Currency, [Inventory Transactions].Levelnumber, [Inventory Transactions].PP, [Inventory Transactions].InvoiceNumber, [Inventory Transactions].InvoiceDate, [Inventory Transactions].Explode, [Inventory Transactions].delevel, [Inventory Transactions].accountID, [Inventory Transactions].DepartmentAutoID, [Inventory Transactions].OrderLine, [Inventory Transactions].PackingOrderID, [Inventory Transactions].ShipFromID, [Inventory Transactions].ShipToID, [Inventory Transactions].UnitsOfMeasure, [Inventory Transactions].[WOB/O], [Inventory Transactions].TaxRate, [Inventory Transactions].isExported, [Inventory Transactions].GLAccount, [Inventory Transactions].SalesUnitPriceConv, [Inventory Transactions].qbTaxCode, [Inventory Transactions].SalesDescription, [Inventory Transactions].qbExportedDate, [Inventory Transactions].ChosenCustomerID, [Inventory Transactions].ChosenShipToID, [Inventory Transactions].BOMAmount, [Inventory Transactions].UnitPriceConv, [Inventory Transactions].UnitsOrderedConv, [Inventory Transactions].UnitsShippedConv, [Inventory Transactions].UnitsShippedFGConv, [Inventory Transactions].UnitsReceivedConv, [Inventory Transactions].UnitsReceivedFGConv, [Inventory Transactions].Categories, [Inventory Transactions].ChosenTransferFromID, [Inventory Transactions].ChosenShipFromID, [Inventory Transactions].SourceTransactionID, [Inventory Transactions].LineAttributes, [Inventory Transactions].LineType, [Inventory Transactions].QtyPerParent, [Inventory Transactions].Cogs
    FROM [Inventory Transactions]
    WHERE ((([Inventory Transactions].RequestforQuotesID)=[forms]![Request for Quotes(inventory)].[tag]));

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Goto Record when Duplicate Record Exists
    By rlsublime in forum Programming
    Replies: 13
    Last Post: 03-22-2012, 03:46 PM
  2. Replies: 5
    Last Post: 03-02-2012, 08:58 PM
  3. Duplicate last record to next record in form
    By jdhaldane in forum Forms
    Replies: 4
    Last Post: 12-17-2010, 04:22 PM
  4. If duplicate record, go to original record
    By BigBear in forum Forms
    Replies: 2
    Last Post: 10-06-2010, 02:58 AM
  5. If duplicate record, go to original record
    By islandboy in forum Access
    Replies: 51
    Last Post: 06-02-2010, 04: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