"Me" command in VB

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

Guest

I am in a form which has a subform, which is viewed as a datasheet of a query
(showing all of my clients). I want to click on 1 record on the subform data
sheet and then click a command button (on the form), which will take me to
that record's client form. This is what I have for the Event Procedure for
the command button:

Private Sub Test_Click()
On Error GoTo Err_Test_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Transaction Detail"
stLinkCriteria = "[Exchange No]=" & "'" & Me![Exchange No] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Test_Click:
Exit Sub

Err_Test_Click:
MsgBox Err.Description
Resume Exit_Test_Click
End Sub

This takes me to the correct form ("Transaction Detail"), but not for the
chosen record. What am I doing wrong?

Thanks.
 
Is Exchange No defined as numeric or text? If numeric, lose the "'" on
either side of the value you're passing.
 
It is defined as text.

Douglas J. Steele said:
Is Exchange No defined as numeric or text? If numeric, lose the "'" on
either side of the value you're passing.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



rfrench said:
I am in a form which has a subform, which is viewed as a datasheet of a
query
(showing all of my clients). I want to click on 1 record on the subform
data
sheet and then click a command button (on the form), which will take me to
that record's client form. This is what I have for the Event Procedure
for
the command button:

Private Sub Test_Click()
On Error GoTo Err_Test_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Transaction Detail"
stLinkCriteria = "[Exchange No]=" & "'" & Me![Exchange No] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Test_Click:
Exit Sub

Err_Test_Click:
MsgBox Err.Description
Resume Exit_Test_Click
End Sub

This takes me to the correct form ("Transaction Detail"), but not for the
chosen record. What am I doing wrong?

Thanks.
 
In the strLinkCriteria, you are referring to (the value) in a Control on the
Main Form, not on the Subform.

Try:

stLinkCriteria = "[Exchange No]='" & Me.SubformCONTROL.Form![Exchange
No] & "'"

Replace SubformCONTROL with the name of the Subform Control. Note that this
may be different from the name of the Form being used as the Subform.
 
Back
Top