Link Criteria and Form

B

Bryan Hughes

Hello,

I have a form with a subfrom in datasheet view that shows Client Names and
ID related to a Case File.

I have a cmdbtn that in theory opens another form based on the Client ID of
the selected record on the subform.

When it opens though it opens to the first record in the table. I am not
sure what is wrong. Here is the code I am using with the cmdbtn:

Private Sub cmdOpenCD_Click()
On Error GoTo Err_cmdOpenCD_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmClient_Details_RO"
strLinkCriteria = "CID =
Forms!frmCase_Management!FST_Case_File_Clients!CID"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenCD_Click:
Exit Sub

Err_cmdOpenCD_Click:
MsgBox Err.Description
Resume Exit_cmdOpenCD_Click

End Sub

Why is not opening the selected record?

Please Help
-Bryan
 
A

Allen Browne

Suggestions.

1. Include the ".Form" bit to refer to the form in the subform control. If
that is new, see:
http://allenbrowne.com/casu-04.html

2. Try concatenating the value of the field into strLinkCritieria:
strLinkCriteria = "CID = " & Me!FST_Case_File_Clients.Form!CID

3. If "CID" is a Text type field, you need extra quotes:
strLinkCriteria = "CID = """ & Me!FST_Case_File_Clients.Form!CID & """"

4. The code will fail if the subform is at a new record, so you may want to
check for that.
 
A

Allen Browne

There may be a difference between the name of the subform control and the
name of the form you load into the control.
Open the main form in design view.
Right-click the edge and choose Properties.
What is the Name property ("Other" tab of Properties box)?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to the newsgroup. (Email address has spurious "_SpamTrap")

Bryan Hughes said:
Allen,
I changed the code to your example, but I keep receiving the following
message "...Can't find the field 'frmFST_Case_File_Clients' referred to in
your expression".

This is how the code looks now:

Private Sub cmdOpenCD_Click()
On Error GoTo Err_cmdOpenCD_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmClient_Details_RO"

stLinkCriteria = "[CID]=" & """ &
Me!frmFST_Case_File_Clients.Form![ClientID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenCD_Click:
Exit Sub

Err_cmdOpenCD_Click:
MsgBox Err.Description
Resume Exit_cmdOpenClient_Click

End Sub

If I change the subform to continuous and place this button on the subform
it works fine

What am I missing?
-Bryan

Allen Browne said:
Suggestions.

1. Include the ".Form" bit to refer to the form in the subform control. If
that is new, see:
http://allenbrowne.com/casu-04.html

2. Try concatenating the value of the field into strLinkCritieria:
strLinkCriteria = "CID = " & Me!FST_Case_File_Clients.Form!CID

3. If "CID" is a Text type field, you need extra quotes:
strLinkCriteria = "CID = """ & Me!FST_Case_File_Clients.Form!CID & """"

4. The code will fail if the subform is at a new record, so you may want to
check for that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to the newsgroup. (Email address has spurious "_SpamTrap")

ID
of
 

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