Parameter Query

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

Guest

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"?
 
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] & """"
 
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"?
 
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"?
 

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

Back
Top