Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    Phil Knapton is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    19
    Thanks for that. I'll try it and let you know how I get on.


    My date field is called [Quote Date] and my quantity field is called [QLI Quantity] so I shouldn't have a problem with reserved names.
    Thanks again.

  2. #17
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Excellent! Let us know how you get on.

  3. #18
    Phil Knapton is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    19
    I Have run the code and got the following message
    Error 3061
    Description: - Too Few Parameters. Expected 2.

    I have edited the field name in the code you supplied (Below) Have I omitted something?
    The tblQuote has updated but the tblQuoteLineItem has not.

    Private Sub Command121_Click()
    '-- Renew the current Quote by duplicating the existing records...
    '-- but giving the new records a fresh QuoteID of their own.
    On Error GoTo Err_Command121_Click
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim MySQL As String
    Dim MyQuoteID As Long
    Dim NewQuoteID As Long
    Set db = CurrentDb
    MyQuoteID = [QuoteID] '-- Directly from the Current Record of the MainForm
    '-- Append a new record to tblQuote table with *almost* all of the same values as the current record
    '-- We let the table create a new AutoNumber [Quote ID] and use the current DATE
    '-- BTW, DATE is a RESERVED word and should *not* be used as a FieldName
    MySQL = "INSERT INTO tblQuote ( [Clientcontactid], [Userid], [companyid], [Siteid] , " & _
    "[quote Date], [quote status], [quote intro text], [quote exit text]) " & _
    "SELECT [Clientcontactid], [Userid], [companyid], [Siteid] , [quote Date], " & _
    "[quote status], [quote intro text], [quote exit text] FROM tblQuote " & _
    "WHERE [QuoteID] = " & MyQuoteID & ";"
    db.Execute MySQL, dbFailOnError
    '-- Get the *new* QuoteID
    Set rs = db.OpenRecordset("SELECT @@IDENTITY AS LastID;")
    NewQuoteID = rs!LastID
    rs.Close
    Set rs = Nothing
    '-- Now we need to duplicate any LineItems associated with the previous quote
    MySQL = "INSERT INTO tblquotelineitem ( [quoteid], [ProdTypeid], [QLI Description] , [QLI qantity], [QLI Cost]) " & _
    "SELECT NewQuoteID,[ProdTypeid], [QLI Description] , [QLI qantity], [QLI Cost] FROM tblquotelineitem " & _
    "WHERE [quoteid] = " & MyQuoteID & ";"
    db.Execute MySQL, dbFailOnError
    '-- You will still need to move your MainForm to the newly created quote
    '-- You can do this with a FindFirst
    '-- The SubForm should follow along with the MainForm
    Exit_Command121_Click:
    On Error Resume Next
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    Exit Sub
    Err_Command121_Click:
    MsgBox "Error Number: " & Err.Number & vbCrLf & _
    "Description: " & Err.Description
    Resume Exit_Command121_Click
    End Sub

  4. #19
    Phil Knapton is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    19
    For info:-
    Fields in tblQuoteLineItem
    LineItemID Autonumber & Primary
    QuoteID - Number
    ProdTypeID - Number
    QLI Description - memo
    QLI Quantity - number
    QLI Cost - Currency

    Thanks again

  5. #20
    Phil Knapton is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    19
    I have corrected an error of mine in the name of the QLI Quantity field and the error code I get now is 3061 - Too few parameters. Expected 1.
    Thanks again

  6. #21
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Which line is highlighted by the Debugger when you get the error?

  7. #22
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Here's what the code looks like when you use the code tags, the "#" on the tool bar:
    Code:
    Private Sub Command121_Click()
    '-- Renew the current Quote by duplicating the existing records...
    '-- but giving the new records a fresh QuoteID of their own.
       On Error GoTo Err_Command121_Click
       Dim db As DAO.Database
       Dim rs As DAO.Recordset
       Dim MySQL As String
       Dim MyQuoteID As Long
       Dim NewQuoteID As Long
       Set db = CurrentDb
       MyQuoteID = [QuoteID]   '-- Directly from the Current Record of the MainForm
       '-- Append a new record to tblQuote table with *almost* all of the same values as the current record
       '-- We let the table create a new AutoNumber [Quote ID] and use the current DATE
       '-- BTW, DATE is a RESERVED word and should *not* be used as a FieldName
       MySQL = "INSERT INTO tblQuote ( [Clientcontactid], [Userid], [companyid], [Siteid] , " & _
               "[quote Date], [quote status], [quote intro text], [quote exit text]) " & _
               "SELECT [Clientcontactid], [Userid], [companyid], [Siteid] , [quote Date], " & _
               "[quote status], [quote intro text], [quote exit text] FROM tblQuote " & _
               "WHERE [QuoteID] = " & MyQuoteID & ";"
       db.Execute MySQL, dbFailOnError
       '-- Get the *new* QuoteID
       Set rs = db.OpenRecordset("SELECT @@IDENTITY AS LastID;")
       NewQuoteID = rs!LastID
       rs.Close
       Set rs = Nothing
       '-- Now we need to duplicate any LineItems associated with the previous quote
       MySQL = "INSERT INTO tblquotelineitem ( [quoteid], [ProdTypeid], [QLI Description] , [QLI qantity], [QLI Cost]) " & _
               "SELECT """ & NewQuoteID & """, [ProdTypeid], [QLI Description] , [QLI qantity], [QLI Cost] FROM tblquotelineitem " & _
               "WHERE [quoteid] = " & MyQuoteID & ";"
       db.Execute MySQL, dbFailOnError
       '-- You will still need to move your MainForm to the newly created quote
       '-- You can do this with a FindFirst
       '-- The SubForm should follow along with the MainForm
    Exit_Command121_Click:
       On Error Resume Next
       rs.Close
       Set rs = Nothing
       Set db = Nothing
       Exit Sub
    Err_Command121_Click:
       MsgBox "Error Number: " & Err.Number & vbCrLf & _
              "Description: " & Err.Description
       Resume Exit_Command121_Click
    End Sub
    Make the change I highlighted in red.

  8. #23
    Phil Knapton is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    19
    That worked perfectly.
    Thanks for all of your help

  9. #24
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Outstanding! Are you ready to use the THread tools and mark this thread as Solved yet?

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

Similar Threads

  1. Multiple records, one form
    By andwhy81 in forum Forms
    Replies: 16
    Last Post: 10-04-2010, 01:12 PM
  2. One Form, Multiple records
    By andwhy81 in forum Forms
    Replies: 3
    Last Post: 09-21-2010, 12:12 PM
  3. Add Multiple Records on One Form
    By William McKinley in forum Forms
    Replies: 7
    Last Post: 08-18-2010, 09:31 AM
  4. Create multiple records with 1 form?
    By bergjes in forum Forms
    Replies: 4
    Last Post: 04-14-2010, 06:16 AM
  5. Trying to create multiple records from a form
    By ed_hollywood in forum Forms
    Replies: 4
    Last Post: 04-02-2010, 10:57 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