Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Minnesota, USA
    Posts
    151
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Carry Forward Selected Values to Next Record Access 2010 32bit

    I have a data input form for transactions. The form has a button to create additional transactions for the same customer. Basic information would be the same on that next transaction (for example, account office and approval date).

    That button saves the current record and creates a new one. How can I carry forward the selected fields to that new record? I tried the code below, but it is not working. This is in the AfterUpdate event.

    DoCmd.RunCommand acCmdSaveRecord
    Dim ctl As Control
    For Each ctl In Me.Controls
    If ctl.Tag = "CarryForward" Then
    ctl.DefaultValue = """" & ctl.Value & """"
    End If
    Next ctl

    I entered CarryForward into the tag property for the fields I want carried forward.

    Behind the command button to create the new record, it just has DoCmd.GoToRecord , , acNewRec

    Thank you for any suggestions.

    Nancy

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts
    Quote Originally Posted by WriterCat View Post
    I have a data input form for transactions. The form has a button to create additional transactions for the same customer. Basic information would be the same on that next transaction (for example, account office and approval date).

    That button saves the current record and creates a new one. How can I carry forward the selected fields to that new record? I tried the code below, but it is not working. This is in the AfterUpdate event.

    DoCmd.RunCommand acCmdSaveRecord
    Dim ctl As Control
    For Each ctl In Me.Controls
    If ctl.Tag = "CarryForward" Then
    ctl.DefaultValue = """" & ctl.Value & """"
    End If
    Next ctl

    I entered CarryForward into the tag property for the fields I want carried forward.

    Behind the command button to create the new record, it just has DoCmd.GoToRecord , , acNewRec

    Thank you for any suggestions.

    Nancy
    For one thing, you are making all the Default Values a text string, which may not be applicable to the particular field. For example, if it is a Date field, your default value should use # and not quotes; that is, the end result should be #11/15/11# and not "11/15/11". In your code, you might want to examine the Data Type to determine how to form the Default Value. Either that or have different Tags, such as "CarryForwardDate", and then act accordingly.

    And here is a tip, seeing """" is nearly impossible to read, and easy to make a mistake. If you want to embed a quote mark use chr(34) so it would look like this: ctl.DefaultValue = chr(34) & ctl.Value & chr(34)

    Or, you can create your own function which can be used anywhere. I use Qu() so I can write: ctl.DefaultValue = Qu() & ctl.Value & Qu()
    Easy to read, hard to make a mistake.

    In any module, put:

    Public Function Qu() as String
    Qu() = chr(34)
    End Function
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Minnesota, USA
    Posts
    151
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks!

    I made separate "carry forward" messages for the data types and now it works.

    Nancy

  4. #4
    Star Lounger tgw7078's Avatar
    Join Date
    Jul 2010
    Location
    Seattle, WA., USA
    Posts
    90
    Thanks
    1
    Thanked 12 Times in 12 Posts
    Hi Nancy,

    Access MVP Allen Browne has two articles that show how to accomplish this goal:

    Assign default values from the last record
    http://allenbrowne.com/ser-24.html

    Duplicate the record in form and subform
    http://allenbrowne.com/ser-57.html
    Tom Wickerath
    Microsoft Access MVP
    4/1/2006 - 3/31/2012

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •