View Single Post
  #7  
Old March 9th, 2010, 04:57 PM posted to microsoft.public.access.gettingstarted
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Pass field value selected in Combo Box to SQL Query

Set the combo box up as follows:

Name: cboTopic

RowSource: SELECT TopicID, Topic FROM Topics ORDER BY Topic;

BoundColumn: 1
ColumnCount: 2
ColumnWidths: 0cm;8cm

If your units of measurement are imperial rather than metric Access will
automatically convert them. The important thing is that the first dimension
is zero to hide the first column and that the second is at least as wide as
the combo box.

The query will then be:

SELECT Sutras.SutraNo, Index.Properties, Sutras.Sutra
FROM Sutras INNER JOIN [Index] ON Sutras.SutraId=Index.SutraId
WHERE Index.TopicId = Forms![YourForm]![cboTopic]
ORDER BY Sutras.SutraNo;

You can then open the query, or better still a form or report based on it,
with code in the AfterUpdate event procedure of the combo box or in the Click
event procedure of a separate button on the form; e.g. to open a form named
frmSutras with the above query as its RowSource you'd something kike the
following code:

Const MESSAGETEXT = "Please select a topic first."

If Not IsNull(Me.[cboTopic]) Then
DoCmd.OpenForm "frmSutras"
Else
MsgBox MESSAGETEXT, vbInformation, "Warning"
End If

Ken Sheridan
Stafford, England

hamsa wrote:
Dear All,

Thank You very much for the reply. I will give the code that I am using below:

SELECT Sutras.SutraNo, Index.Properties, Sutras.Sutra
FROM Sutras INNER JOIN [Index] ON Sutras.SutraId=Index.SutraId
WHERE (((Index.TopicId) In (SELECT Topics.TopicId FROM Topics WHERE Topics.
Topic = [Enter the Dhatu Name (Ex: - bhü)] )))
ORDER BY Sutras.SutraNo;

In the Inner SELECT statement, I have the code [Enter the Dhatu Name (Ex: -
bhü)] after =.
I want to remove this and instead use the value in the column of the row
selected in the combo box.
How do I do that? I can use either a Combo box event like On Change or I can
also have an EXECUTE button which when clicked will pass the value from the
combo box to the Inner SELECT statement of the SQl query. My requirement is
that I have to avoid the parameter popup window as the user has already
selected the row in the combo box.

I retained the present code as I coult not figure out how to pass the value
from the combo box to the SQL query.

After a row is selected in the combo box, I want the value of the column in
the row selected passed as the selection criteria to the Inner SELECT.

At present, the COmbo box Control source property is blank and the Bound
Column property is set to 1.

Normally, you would refer to the control in the query. The form must be open
when the query executes. For a combobox that will return the value of the row

[quoted text clipped - 27 lines]

Thanks in Advance.


--
Message posted via http://www.accessmonster.com