Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Posts
    300

    Unanswered: Data in Field not copied to new record

    I have a main form with a unique number and I click on a command button to open another form to enter in a date and a note for the main record. When I click on the ADD RECORD command button, it does open a new record but I want the Unique number from the main record to automatically populate the field in the detail record, but I cannot figure how to do that..

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    To open the second form from the first form:
    Code:
    docmd.OpenForm "<FormName>",,,,acFormAdd,,CStr(Me.<Control>.Value)
    In the second form:
    Code:
    Private Sub Form_Open()
        Me.<Control>.Value = Me.OpenArgs
    End Sub
    Have a nice day!

  3. #3
    Join Date
    Nov 2003
    Posts
    300

    Cool

    Thank you for the information. Can you tell me which control name should go where? Here is what I am currently using to tie the two forms together now:

    Private Sub Command74_Click()
    On Error GoTo Err_Command74_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmUWHistoryDetail"

    stLinkCriteria = "[UAIDNumber]=" & Me![UA ID Number]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_Command74_Click:
    Exit Sub

    Err_Command74_Click:
    MsgBox Err.Description
    Resume Exit_Command74_Click

    End Sub
    _____________

    So now you are saying that I should have:

    Docmd.OpenForm "frmUWHistoryDetail",,,,acFormAdd,,CStr(Me.[UAIDNumber].Value)

    Is this correct?

    and this in the 2nd form?

    Private Sub Form_Open()
    Me.[UAIDNumber].Value = Me.OpenArgs
    End Sub

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    In the first form, <Control> is the name of the control containing the Unique number from the main record. In the second form, <Control> is the name of the control that should receive the value from the first form.
    Have a nice day!

Posting Permissions

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