Opening Main form with subform (filtered)

G

Guest

Hi,

I have a search function in my db which puts the results into a list box.
When double clicking on the result, I want to be able to open the main form
with the subform at the correct record. The code I have is:

Dim strProjId As String
Dim strCustId As String

strProjId = Results.Column(1)
strCustId = Results.Column(4)

DoCmd.OpenForm "Customer", WhereCondition:="[Customer_ Id] = " & strCustId
Forms!Customer!Project.Form.Filter = "Project_Id " & strProjId
Forms!Customer!Project.Form.FilterOn = True

End Sub

Customer ID is the ID of the main form and is a number.
Project ID id the ID of the subform and is alphnumeric.

The error always occurs on:

Forms!Customer!Project.Form.Filter = "Project_Id " & strProjId

and I've been getting various errors..

I've tripple checked the code and as far as I can see it is correct, so it's
possibly something else in the db that's causing the problem?
Any suggestions gratefully received,

Thanks
 
G

Guest

ooops! sorry, I mistyped when I posted. The actual code does have the = in
but still doesn't work. Thanks for your reply though.

Rob Oldfield said:
Try

Forms!Customer!Project.Form.Filter = '"Project_Id " & strProjId&"'"


Helen said:
Hi,

I have a search function in my db which puts the results into a list box.
When double clicking on the result, I want to be able to open the main form
with the subform at the correct record. The code I have is:

Dim strProjId As String
Dim strCustId As String

strProjId = Results.Column(1)
strCustId = Results.Column(4)

DoCmd.OpenForm "Customer", WhereCondition:="[Customer_ Id] = " & strCustId
Forms!Customer!Project.Form.Filter = "Project_Id " & strProjId
Forms!Customer!Project.Form.FilterOn = True

End Sub

Customer ID is the ID of the main form and is a number.
Project ID id the ID of the subform and is alphnumeric.

The error always occurs on:

Forms!Customer!Project.Form.Filter = "Project_Id " & strProjId

and I've been getting various errors..

I've tripple checked the code and as far as I can see it is correct, so it's
possibly something else in the db that's causing the problem?
Any suggestions gratefully received,

Thanks
 
R

Rob Oldfield

Hmm. I didn't even notice the missing =. My response was about adding the
apostrophes...and the missing = did actually throw my syntax out.

Forms!Customer!Project.Form.Filter = "Project_Id ='" & strProjId & "'"



Helen said:
ooops! sorry, I mistyped when I posted. The actual code does have the = in
but still doesn't work. Thanks for your reply though.

Rob Oldfield said:
Try

Forms!Customer!Project.Form.Filter = '"Project_Id " & strProjId&"'"


Helen said:
Hi,

I have a search function in my db which puts the results into a list box.
When double clicking on the result, I want to be able to open the main form
with the subform at the correct record. The code I have is:

Dim strProjId As String
Dim strCustId As String

strProjId = Results.Column(1)
strCustId = Results.Column(4)

DoCmd.OpenForm "Customer", WhereCondition:="[Customer_ Id] = " & strCustId
Forms!Customer!Project.Form.Filter = "Project_Id " & strProjId
Forms!Customer!Project.Form.FilterOn = True

End Sub

Customer ID is the ID of the main form and is a number.
Project ID id the ID of the subform and is alphnumeric.

The error always occurs on:

Forms!Customer!Project.Form.Filter = "Project_Id " & strProjId

and I've been getting various errors..

I've tripple checked the code and as far as I can see it is correct,
so
it's
possibly something else in the db that's causing the problem?
Any suggestions gratefully received,

Thanks
 

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