Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Phil Knapton is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    19

    Renew Multiple records via a form


    I have a quotations database where a quote form writes to 2 tables (Quote table and quote line table through a subform). How do I put a renew button on the quote form which will create a new record in the quotation table and multiple new records in the quote line table

  2. #2
    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
    Assuming your MainForm and SubForm are linked properly and the SubForm is in Continuous form view, then simply moving the mainForm to a new record should do what you are asking. No code required.

  3. #3
    Phil Knapton is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    19

    Thanks for the prompt reply

    If I view a record (a quotation that was entered 12 months ago) in the form then I would want to raise a new unique quote and possibly change the prices - how would i go about doing that? I may be misunderstanding your reply here but I can see any preset controls to create a new record based on details in a form and a subform that cover 2 tables.
    Form details fields :- tblQuote
    Quote ID (primary)
    Client id
    User id
    Quoting company id
    Site id
    date
    quote status
    quote intro text
    quote exit text

    Subform: -tblquotelineitems
    quotelineitemid
    quoteid
    catagoryid
    description
    qty
    value

    I dont want to have to re-enter all the details in the renewal quote as the qty of lines in the quote can be up to 50 and they are memo fields.
    This is a services quote rather than a product so the line detail is very specific to the client and site

  4. #4
    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
    It sounds like you really want to duplicate the quote as a new quote. Is that true?

  5. #5
    Phil Knapton is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    19
    yes that is true

  6. #6
    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
    Hmm...you need a new Quote record that duplicates a current record but has a new QuoteID and then all of the quote detail records need to be duplicated with the new QuotID number. Is that an accurate description of what you need?

  7. #7
    Phil Knapton is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    19
    Yes that is exactly what I am looking for.
    Are you able to point me in the right direction?

  8. #8
    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
    I'll give it some more thought but it sounds like a job for a code procedure. How comfortable are you with code?

  9. #9
    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
    Is the QuoteID field in the tblQuote table an AutoNumber field? I assume the quotelineitemid in the tblquotelineitems table is also an AutoNumber field.

  10. #10
    Phil Knapton is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    19
    QuoteID is autonumber and primary
    QuoteLineItemID is autonumber and primary

  11. #11
    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
    Good design! I'll give it some thought as to the Procedure needed. Memo field huh? I hope they are not a problem. You need more that 256 characters for these descriptions?

  12. #12
    Phil Knapton is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    19
    Thanks
    The justification of text in the memo field was a pain to start with until I found Lebans code and that seems to work fine.
    The majority of the quotations are for service contracts that cover the control of legionnaires disease in buildings. There needs to be a lot of text to cover the exact services offered. 1 "lineItem" of the quote can be a page of text.

  13. #13
    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
    I'll take your word for it. Here's some issues that may crop up and need to be delt with: http://allenbrowne.com/ser-63.html

  14. #14
    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
    BTW, as I'm writing this procedure it becomes obvious you have use DATE and VALUE as Field names. Not a good idea. You can work around that with [brackets] but better to rename them. http://www.allenbrowne.com/AppIssueBadWord.html

  15. #15
    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
    Remember this is <<< AIR CODE >>> so use at your own risk! This is my idea of the MainForm button code for what you requested. I used the field names you supplied in post #3.
    Code:
    Private Sub cmdReQuote_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_cmdReQuote_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 = [Quote ID]     '-- 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 ( [Client id], [User id], [Quoting company id], [Site id] , " & _
               "[Date], [quote status], [quote intro text], [quote exit text]) " & _
               "SELECT [Client id], [User id], [Quoting company id], [Site id] , Date, " & _
               "[quote status], [quote intro text], [quote exit text] FROM tblQuote " & _
               "WHERE [Quote ID] = " & 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 tblquotelineitems ( quoteid, catagoryid, Description , qty, [Value]) " & _
               "SELECT NewQuoteID, catagoryid, Description , qty, [Value] FROM tblquotelineitems " & _
               "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_cmdReQuote_Click:
       On Error Resume Next
       rs.Close
       Set rs = Nothing
       Set db = Nothing
       Exit Sub
    Err_cmdReQuote_Click:
       MsgBox "Error Number: " & Err.Number & vbCrLf & _
              "Description:  " & Err.Description
       Resume Exit_cmdReQuote_Click
    End Sub

Page 1 of 2 12 LastLast
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