Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Inputing Data from one form to another

Discussion in 'Information Technology' started by Tdahlman, Jul 28, 2006.

  1. Tdahlman

    Tdahlman
    Expand Collapse
    Guest

    I have a form A where it assignes an ID whenever I start a new entry. I put a
    command button to open a new Form B where the ID in Form A is the common
    field for both forms. My form B however doesn't link properly and nothing of
    my entries from form A will show in Form B.

    My code looks like this:

    Private Sub cmdNext_Click()
    On Error GoTo Err_cmdNext_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frm_QuoteDetails"

    stLinkCriteria = "[OrderInfoID]=" & Me![OrderInfoID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_cmdNext_Click:
    Exit Sub

    Err_cmdNext_Click:
    MsgBox Err.Description
    Resume Exit_cmdNext_Click

    End Sub

    Please Advise.
    Thanks in advance
    Travis
     
  2. Loading...


  3. Ken Sheridan

    Ken Sheridan
    Expand Collapse
    Guest

    "Tdahlman" wrote:

    > I have a form A where it assignes an ID whenever I start a new entry. I put a
    > command button to open a new Form B where the ID in Form A is the common
    > field for both forms. My form B however doesn't link properly and nothing of
    > my entries from form A will show in Form B.
    >
    > My code looks like this:
    >
    > Private Sub cmdNext_Click()
    > On Error GoTo Err_cmdNext_Click
    >
    > Dim stDocName As String
    > Dim stLinkCriteria As String
    >
    > stDocName = "frm_QuoteDetails"
    >
    > stLinkCriteria = "[OrderInfoID]=" & Me![OrderInfoID]
    > DoCmd.OpenForm stDocName, , , stLinkCriteria
    >
    > Exit_cmdNext_Click:
    > Exit Sub
    >
    > Err_cmdNext_Click:
    > MsgBox Err.Description
    > Resume Exit_cmdNext_Click
    >
    > End Sub
    >
    > Please Advise.
    > Thanks in advance
    > Travis
     
  4. Mushroom

    Mushroom
    Expand Collapse
    Guest

    I don't know if Ken answered this or not. His reply looked blank to me which
    could just be a bug in the newsreader.

    As for your question, it seems that if you create a new record then open a
    form linked to that PK, the form will be blank until you have saved the
    record. You may need to place a command in your code to force save the
    record before opening the second form.

    my 2 cents...
    --
    Kept in the dark and fed crap all the time.


    "Tdahlman" wrote:

    > I have a form A where it assignes an ID whenever I start a new entry. I put a
    > command button to open a new Form B where the ID in Form A is the common
    > field for both forms. My form B however doesn't link properly and nothing of
    > my entries from form A will show in Form B.
    >
    > My code looks like this:
    >
    > Private Sub cmdNext_Click()
    > On Error GoTo Err_cmdNext_Click
    >
    > Dim stDocName As String
    > Dim stLinkCriteria As String
    >
    > stDocName = "frm_QuoteDetails"
    >
    > stLinkCriteria = "[OrderInfoID]=" & Me![OrderInfoID]
    > DoCmd.OpenForm stDocName, , , stLinkCriteria
    >
    > Exit_cmdNext_Click:
    > Exit Sub
    >
    > Err_cmdNext_Click:
    > MsgBox Err.Description
    > Resume Exit_cmdNext_Click
    >
    > End Sub
    >
    > Please Advise.
    > Thanks in advance
    > Travis
     
  5. Ken Sheridan

    Ken Sheridan
    Expand Collapse
    Guest

    Travis:

    Sorry about the blank post; inadvertently clicked the 'Post' button.

    I'm not sure I fully understand what you say, but using the WhereCondition
    argument of the OpenForm method will open the second form filtered to those
    records where the ID matches the current ID in the first form. It won't
    automatically add that ID to new records which you create in the second form.
    You have to specifically set the DefaultValue property of the control on the
    second form. You can do this by passing the value as the OpenArgs property
    of the second form like so:

    DoCmd.OpenForm stDocName, , , stLinkCriteria,,,Me.OrderInfoID

    or more readably:

    DoCmd.OpenForm _
    FormName:=stDocName, _
    WhereCondition:=stLinkCriteria, _
    OpenArgs:=Me.OrderInfoID

    In the second form's Open event procedure put:

    If Not IsNull(Me.OpenArgs) Then
    Me.OrderInfoID.DefaultValue = """" & Me.OpenArgs & """"
    End If

    The foreign key OrderInfoID in the second form's underlying table must not
    be an autonumber field of course, but a straightforward long integer number
    data type.

    Note that the DefaultValue property of a control is a string expression
    regardless of the data type; hence the delimiting literal quotes.

    Ken Sheridan
    Stafford, England

    "Tdahlman" wrote:

    > I have a form A where it assignes an ID whenever I start a new entry. I put a
    > command button to open a new Form B where the ID in Form A is the common
    > field for both forms. My form B however doesn't link properly and nothing of
    > my entries from form A will show in Form B.
    >
    > My code looks like this:
    >
    > Private Sub cmdNext_Click()
    > On Error GoTo Err_cmdNext_Click
    >
    > Dim stDocName As String
    > Dim stLinkCriteria As String
    >
    > stDocName = "frm_QuoteDetails"
    >
    > stLinkCriteria = "[OrderInfoID]=" & Me![OrderInfoID]
    > DoCmd.OpenForm stDocName, , , stLinkCriteria
    >
    > Exit_cmdNext_Click:
    > Exit Sub
    >
    > Err_cmdNext_Click:
    > MsgBox Err.Description
    > Resume Exit_cmdNext_Click
    >
    > End Sub
    >
    > Please Advise.
    > Thanks in advance
    > Travis
     

Share This Page