"Me" command in VB

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.
 
D

Douglas J. Steele

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

Guest

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.
 
V

Van T. Dinh

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top