Adding a combo box in a query

  • Thread starter Thread starter Ammo
  • Start date Start date
A

Ammo

Hi,

I have query 'qry_GrantPotAllocation'. In the query is a
field called 'GrantPotName'.

On running the query, how I can I display only those
records associated to what I select in 'GrantPotName'
combobox? Is it possible to have a combobox in a query,
instead of having to type in the exact field value to
display a particular set of records?

Best Wishes

Amarjeet
 
the standard way to do this is to create an unbound form, which i'll call
frmPickName. add an unbound combo box, which i'll call cboPotNames. set the
RowSource of the combo box to the table, query or list of values that will
give you the GrantPotNames you want to choose from. set a criteria in your
query as

WHERE GrantPotName = Forms!frmPickName!cboPotNames

add a command button to the form with the following code in the OnClick
event procedure (to open your query after a value is chosen from the combo
box droplist), as

If Not IsNull(Me!cboPotNames) Then
DoCmd.OpenQuery "NameOfYourQuery"
Else
Msgbox "Please select a Grant Pot Name from the droplist."
End If

substitute the correct name of the query, of course.

hth
 
Hi Tina,

Thank you for your reply, I have done exactly what you
said, but it is still not working. The query produces
blank results (no records displayed). The query is made up
of two tables with a one to many relationship. I
understand the logic in your solution, but still cannot
figure out why it is still not working. Hope you can help
again?

Cheers

Amarjeet
 
first, does the query return records when you DON'T use any criteria? pls
check that, and post the query's SQL statement, and the RowSource of the
combo box.
 
when I add the where GrantPotName = Forms!frm_PickGrantPot!
cbo_GrantPotName statement I get no returned results, the
SQL statement is as follows:

SELECT [tbl_GrantPot].[GrantPotNumber], [tbl_GrantPot].
[GrantPotName], [tbl_GrantPot].[AvailableGrant],
[tbl_GrantAllocation].[GrantAllocationNumber],
[tbl_GrantAllocation].[DateGrantAllocated],
[tbl_GrantAllocation].[GrantRecipient],
[tbl_GrantAllocation].[ReasonGrantAllocated],
[tbl_GrantAllocation].[AmountGrantAllocated],
[tbl_GrantAllocation].[GrantSpendProgress]
FROM tbl_GrantPot INNER JOIN tbl_GrantAllocation ON
[tbl_GrantPot].[GrantPotNumber]=[tbl_GrantAllocation].
[GrantPotNumber]
WHERE (("where GrantPotName"=[Forms]![frm_PickGrantPot]!
[cbo_GrantPotName]));
 
SELECT [tbl_GrantPot].[GrantPotNumber], [tbl_GrantPot].
[GrantPotName], [tbl_GrantPot].[AvailableGrant],
[tbl_GrantAllocation].[GrantAllocationNumber],
[tbl_GrantAllocation].[DateGrantAllocated],
[tbl_GrantAllocation].[GrantRecipient],
[tbl_GrantAllocation].[ReasonGrantAllocated],
[tbl_GrantAllocation].[AmountGrantAllocated],
[tbl_GrantAllocation].[GrantSpendProgress]
FROM tbl_GrantPot INNER JOIN tbl_GrantAllocation ON
[tbl_GrantPot].[GrantPotNumber]=[tbl_GrantAllocation].[GrantPotNumber]
WHERE GrantPotName=[Forms]![frm_PickGrantPot]![cbo_GrantPotName]
when I add the where GrantPotName = Forms!frm_PickGrantPot!
cbo_GrantPotName statement I get no returned results, the
SQL statement is as follows:

SELECT [tbl_GrantPot].[GrantPotNumber], [tbl_GrantPot].
[GrantPotName], [tbl_GrantPot].[AvailableGrant],
[tbl_GrantAllocation].[GrantAllocationNumber],
[tbl_GrantAllocation].[DateGrantAllocated],
[tbl_GrantAllocation].[GrantRecipient],
[tbl_GrantAllocation].[ReasonGrantAllocated],
[tbl_GrantAllocation].[AmountGrantAllocated],
[tbl_GrantAllocation].[GrantSpendProgress]
FROM tbl_GrantPot INNER JOIN tbl_GrantAllocation ON
[tbl_GrantPot].[GrantPotNumber]=[tbl_GrantAllocation].
[GrantPotNumber]
WHERE (("where GrantPotName"=[Forms]![frm_PickGrantPot]!
[cbo_GrantPotName]));
-----Original Message-----
first, does the query return records when you DON'T use any criteria? pls
check that, and post the query's SQL statement, and the RowSource of the
combo box.





.
 
ah, thank heavens for the calvary, arriving in the nick of time! :)


John Spencer (MVP) said:
SELECT [tbl_GrantPot].[GrantPotNumber], [tbl_GrantPot].
[GrantPotName], [tbl_GrantPot].[AvailableGrant],
[tbl_GrantAllocation].[GrantAllocationNumber],
[tbl_GrantAllocation].[DateGrantAllocated],
[tbl_GrantAllocation].[GrantRecipient],
[tbl_GrantAllocation].[ReasonGrantAllocated],
[tbl_GrantAllocation].[AmountGrantAllocated],
[tbl_GrantAllocation].[GrantSpendProgress]
FROM tbl_GrantPot INNER JOIN tbl_GrantAllocation ON
[tbl_GrantPot].[GrantPotNumber]=[tbl_GrantAllocation].[GrantPotNumber]
WHERE GrantPotName=[Forms]![frm_PickGrantPot]![cbo_GrantPotName]
when I add the where GrantPotName = Forms!frm_PickGrantPot!
cbo_GrantPotName statement I get no returned results, the
SQL statement is as follows:

SELECT [tbl_GrantPot].[GrantPotNumber], [tbl_GrantPot].
[GrantPotName], [tbl_GrantPot].[AvailableGrant],
[tbl_GrantAllocation].[GrantAllocationNumber],
[tbl_GrantAllocation].[DateGrantAllocated],
[tbl_GrantAllocation].[GrantRecipient],
[tbl_GrantAllocation].[ReasonGrantAllocated],
[tbl_GrantAllocation].[AmountGrantAllocated],
[tbl_GrantAllocation].[GrantSpendProgress]
FROM tbl_GrantPot INNER JOIN tbl_GrantAllocation ON
[tbl_GrantPot].[GrantPotNumber]=[tbl_GrantAllocation].
[GrantPotNumber]
WHERE (("where GrantPotName"=[Forms]![frm_PickGrantPot]!
[cbo_GrantPotName]));
-----Original Message-----
first, does the query return records when you DON'T use any criteria? pls
check that, and post the query's SQL statement, and the RowSource of the
combo box.


Hi Tina,

Thank you for your reply, I have done exactly what you
said, but it is still not working. The query produces
blank results (no records displayed). The query is made up
of two tables with a one to many relationship. I
understand the logic in your solution, but still cannot
figure out why it is still not working. Hope you can help
again?

Cheers

Amarjeet



-----Original Message-----
the standard way to do this is to create an unbound form,
which i'll call
frmPickName. add an unbound combo box, which i'll call
cboPotNames. set the
RowSource of the combo box to the table, query or list of
values that will
give you the GrantPotNames you want to choose from. set a
criteria in your
query as

WHERE GrantPotName = Forms!frmPickName!cboPotNames

add a command button to the form with the following code
in the OnClick
event procedure (to open your query after a value is
chosen from the combo
box droplist), as

If Not IsNull(Me!cboPotNames) Then
DoCmd.OpenQuery "NameOfYourQuery"
Else
Msgbox "Please select a Grant Pot Name from the
droplist."
End If

substitute the correct name of the query, of course.

hth


message
Hi,

I have query 'qry_GrantPotAllocation'. In the query is a
field called 'GrantPotName'.

On running the query, how I can I display only those
records associated to what I select in 'GrantPotName'
combobox? Is it possible to have a combobox in a query,
instead of having to type in the exact field value to
display a particular set of records?

Best Wishes

Amarjeet


.



.
 
Back
Top