Passing info to a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a main form with a button on it that calls another form. The button
has the following code:

==================================

Private Sub Add_new_payment_Click()
On Error GoTo Err_Add_new_payment_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Frm_Payments"

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

Exit_Add_new_payment_Click:
Exit Sub

Err_Add_new_payment_Click:
MsgBox Err.Description
Resume Exit_Add_new_payment_Click

End Sub
========================

Currently when there is already payments associated with the group ID it
will pull all those payments and the form will open on the first record it
found. However if there is no payments, the form opens with the group ID as
zero.

I need the button to do two things:
1. populate the "Group ID" field with the same group ID from the record I
was on when I hit the button.
2. when there are more than one record it should pull all the records and
automatically also go to a new record with the group ID populated (basically
add a new payment but also pull the existing ones as it does now).

Can anyone take a swing at adjusting the code to do that. I would greatly
appreciate it. Thank you in advance.

Wael.
 
On the Open command you can send an open args that includes the Current GroupID

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

===================================
On the load event of the second form write the code

DoCmd.GoToRecord , , acNewRec
Me![GroupID Field Name In the second form] = Me.OpenArgs
 
Besides using OpenArgs as Ofer suggested, you can simply use the
DefaultValue property of the GroupID field textbox by using the expression:

=[Forms]![NameOfFirstForm]![GroupID]

The DefaultValue property only comes into play when there is a brand new
record.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Back
Top