Parameter Query

L

Larry G.

If I am using a form to navigate through information, and I want to have a
button that will display all of the correspondence related to just that site.
When I design the query, how do I get the parameter to enter based on the
site number that is currently displayed on the form so that the user just has
to click the button "View Correspondence"?
 
A

Allen Browne

Use the WhereCondition of OpenForm to limit the target form to just the
correspondence for the site.

This kind of thing:
Dim strWhere As String
If Not IsNull(Me.[SiteNumber]) Then
strWhere = "[SiteNumber] = " & Me.[SiteNumber]
End If
DoCmd.OpenForm "Correspondence", WhereCondition:= strWhere

Note: If SiteNumber is a Text field (not a Number field) you need extra
quotes:
strWhere = "[SiteNumber] = """ & Me.[SiteNumber] & """"
 
L

Larry G.

I am a little confused, where should this code go? if I am creating a Macro
for the button using the OpenForm, I see the WhereCondition, but where do I
put the code you provided?

Allen Browne said:
Use the WhereCondition of OpenForm to limit the target form to just the
correspondence for the site.

This kind of thing:
Dim strWhere As String
If Not IsNull(Me.[SiteNumber]) Then
strWhere = "[SiteNumber] = " & Me.[SiteNumber]
End If
DoCmd.OpenForm "Correspondence", WhereCondition:= strWhere

Note: If SiteNumber is a Text field (not a Number field) you need extra
quotes:
strWhere = "[SiteNumber] = """ & Me.[SiteNumber] & """"

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

Reply to group, rather than allenbrowne at mvps dot org.

Larry G. said:
If I am using a form to navigate through information, and I want to have a
button that will display all of the correspondence related to just that
site.
When I design the query, how do I get the parameter to enter based on the
site number that is currently displayed on the form so that the user just
has
to click the button "View Correspondence"?
 
A

Allen Browne

Set the On Click property of you command button to:
[Event Procedure]

Click the Build button (...) beside the property.
Access opens the Code window.

Put the code in there, between the "Private Sub ..." and "End Sub" lines.

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

Reply to group, rather than allenbrowne at mvps dot org.

Larry G. said:
I am a little confused, where should this code go? if I am creating a Macro
for the button using the OpenForm, I see the WhereCondition, but where do
I
put the code you provided?

Allen Browne said:
Use the WhereCondition of OpenForm to limit the target form to just the
correspondence for the site.

This kind of thing:
Dim strWhere As String
If Not IsNull(Me.[SiteNumber]) Then
strWhere = "[SiteNumber] = " & Me.[SiteNumber]
End If
DoCmd.OpenForm "Correspondence", WhereCondition:= strWhere

Note: If SiteNumber is a Text field (not a Number field) you need extra
quotes:
strWhere = "[SiteNumber] = """ & Me.[SiteNumber] & """"


Larry G. said:
If I am using a form to navigate through information, and I want to
have a
button that will display all of the correspondence related to just that
site.
When I design the query, how do I get the parameter to enter based on
the
site number that is currently displayed on the form so that the user
just
has
to click the button "View Correspondence"?
 
Top