Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connect record in current form to form being opened

Status
Not open for further replies.

jjb373

MIS
Feb 4, 2005
95
US
I have a 2 forms.

One form EnterScores, is my main form where a user can enter, update, or view a record and its data(fields).

I have created 3 macros to open additional forms for analysis purposes. On the form EnterScores, I have a combo box which allows the user to select one of the 3 forms. I also have a button on the form which I have added VB code to.
The code for the button opens the one of the 3 forms depending on which name was selected in the combo box.

Basically the user selects one of the 3 forms names from the combo box then clicks on the button and the desired form opens.


What I want to do is this:
I have 10 records and I scroll through the navigation buttons to the 5th record on the EnterScores form. I now want to view one of my analysis forms (one of the 3 forms the user can select from the combo box) and have the forms that opens, open straight to that 5th record.

How can I connect the form I am opening to the main form? Can I add some VB code to my 'on click' event to connect the two?

Thanks!

Here is my code:
Private Sub btnGo_Click()
On Error GoTo Err_btnMacro_Click

Dim stDocName As String

If txtFromSelection = "Past Rounds" Then
stDocName = "OpenFormPastRounds"
DoCmd.RunMacro stDocName

ElseIf txtFormSelection = "Scoring Breakdown" Then
stDocName = "OpenFormScoringBreakdown"
DoCmd.RunMacro stDocName

ElseIf txtFormSelection = "Round Statistics" Then
stDocName = "OpenFormRoundStatistics"
DoCmd.RunMacro stDocName

End If

Exit_btnMacro_Click:
Exit Sub

Err_btnMacro_Click:
MsgBox Err.Description
Resume Exit_btnMacro_Click


End Sub

Cheers,

JJB373
 
Try using Docmd.OpenForm instead of using macros. The last parameter for the OpenForm call allows you to pass OpenArgs to the next form. You can pass the ID for your 5th record with the OpenArgs parameter.

Code:
If txtFromSelection = "Form 2" Then
   DoCmd.OpenForm "Form2",,,,,,txtRecordID.Value
End If

Then, on your second form, in the On Open event, retrieve "Me.OpenArgs" to get the record id, and open that record.
 
Do I add the DoCmd.OpenForm to the button on the main data form (the forms I want to pull the record from)??

Also, on the second form's On Open event, do I only need to enter the code: Me.OpenArgs


Thank you very much for your help!

Cheers,

JJB373
 
Yes, you add the Docmd.openform to the button on your main form. On the second form's on open event, Me.OpenArgs will only have the ID of the record you want opened. You would need to do some programagic to get it to navigate itself to the desired record. For example, you could set the second form's Filter to the desired record (assuming you already have a record source set).
Code:
Me.Filter = "ID=" & Me.OpenArgs

Where the ID is the name of the key field in your table.
 
With that help and some side coding I got it. Thank you very much.

Cheers,

JJB373
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top