View Full Version : Queried Form Results Open Another Form to Specific Record


ewong1
04-27-2005, 10:45 AM
I currently have two forms: frmE_SAFind and frmE_SAOrderDataEntry

frmE_SAFind shows results from a query including fields [txtIDPO] and [dtmDate]
Example:
btnOpnFrm IDPO Date
btnOpnFrm 6543 2/1/05
btnOpnFrm 5681 1/1/05

frmE_SAOrder shows order details including [txtIDPO] and [dtmDate]

I have a open form command button set up on [frmE_SAFind] that opens [frmE_SAOrderDataEntry].

Here is the existing Code in my OnClick() Command:

Private Sub btnOpenForm_Click()
On Error GoTo Err_btnOpenForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmE_SAOrderDataEntry"

If IsNull(Me!IDPO) Then
MsgBox "Select a valid PO."
Exit Sub
Else
stLinkCriteria = "[IDPO]=" & "'" & Me![IDPO] & "'"
End If

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_btnOpenForm_Click:
Exit Sub

Err_btnOpenForm_Click:
MsgBox Err.Description
Resume Exit_btnOpenForm_Click

End Sub

Is it possible for me to modify its properties so that when the open form command button is clicked, the order details in [frmE_SAOrder] will represent the order that the user is selecting via the btnOpnFrm command?

Example: If I click btnOpnFrm for 6543, [frmE_SAOrderDataEntry] will show me PO 6543 details.

Hopefully I made myself clear enough to understand. Thanks for your help!

Pat Hartman
04-27-2005, 06:58 PM
Are you saying that the button is on the main form but the record you want to see is on a subform? If so, you need to reference the key field in the subform:

stLinkCriteria = "[IDPO]=" & "'" & Me.YourSubform.Form![IDPO] & "'"

Of course you'll need to change the If so that it checks this field for null rather than the one on the mainform.

When I do this, I don't use a button. I add the code to the double-click event of the key or name field of the subform record. That avoids all confusion since there is ALWAYS a record selected and the selection is clear to the user. Buttons on one form that require data on a different form are a problem waiting to happen.