Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2012
    Posts
    29

    Unanswered: refreshing a form using passed vaules

    Good evening,
    I have a form that opens with passed values from a previous form. The form opens with 3 values from the previous form. User enters required data, saves record. I need to refresh the form (via a command button) so that those same initial 3 values are still there and the user can add another record .
    IE, customer is adding a car to an existing contact, needs to save the record and add another car to same contact.
    I thought a simple macro to close on reopen the form would work, because closing the form manually and opening it again from the parent form works. However I get and "Invalid Use of Null" error.

    Code (provided by missinglinq, works fine) to open the form initially from the parent form:

    In the First, calling Form
    Code:

    Private Sub OpenSecondForm_Click()
    DoCmd.OpenForm "FormB", , , , , , Me.FieldA & ";" & Me.FieldB
    End Sub

    In the Second, called Form
    Code:

    Private Sub Form_Load()
    MyOpenArgs = Split(Me.OpenArgs, ";")
    If Not IsNull(Me.OpenArgs) Then
    DoCmd.GoToRecord , , acNewRec
    Me.Field1 = MyOpenArgs(0)
    Me.Field2 = MyOpenArgs(1)
    End If
    End Sub


    Any thoughts? Again, I am a complete novice with VBA
    Last edited by Rayce; 02-25-12 at 14:32. Reason: missing text

  2. #2
    Join Date
    Jan 2012
    Posts
    97
    Rayce,

    One possible solution is to run the following code on the save button:

    Code:
    'Declare a variable to pass the value before adding new record
    Dim OldVal As String
    'save record
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    'set variable to value
    OldVal = Me.control.Value
    'add new record
    DoCmd.GoToRecord , , acNewRec
    'set control to variable
    Me.control.Value = OldVal
    This would need to be replicated for each value you would want to be passed.
    Hope this helps,

    Dave.

    _____________

    Access 2000 User

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Just to be sure, from FormA, you now want to open FormB, and then add one or more Records in FormB?

    If so, you'll need to delete the current Form_Load code for the Second, called Form, and use this:
    Code:
    Private Sub Form_Load()
       DoCmd.GoToRecord , , acNewRec
    End Sub
    Code:
    Private Sub Form_Current()
      If Me.NewRecord Then
        If Not IsNull(Me.OpenArgs) Then
          MyOpenArgs = Split(Me.OpenArgs, ";")
          Me.Field1 = MyOpenArgs(0)
          Me.Field2 = MyOpenArgs(1)
       End If
      End If
    End Sub
    Any New Records made, until you close FormB, will now have the passed Values.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Feb 2012
    Posts
    29
    MissingLinq,
    This relates to the same issue you helped me with earlier in the week. To clarify
    FormA has 20+fields. On open formB, data from fields 1,2,& 3 gets passed from FormA to FormB (per code you provided). User enters balance of data for that record in FormB, then clicks on Command Button that saves record to TableB.
    Now user needs to enter another record that ties to the same info as the previous entry (associating another vehicle to the same contact). What I want to accomplish is bringing the data from the same 3 fields (originally in FormA) that were passed to FormB when it was initially opened. User can now enter additional info into FormB and again save record. Rinse & repeat as many times as necessary until user needs to go back to FormA for a new contact.
    Hopefully that is clearer.

Posting Permissions

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