|
 |
access thread: SQL and Combo Boxes
Message #1 by markusb@m... on Wed, 11 Jul 2001 10:44:01
|
|
Hi,
I wish to use a Combo Box to allow users of an access 97 database to
select not only a specific row but also which column should be displayed
by a query.
The WHERE-function has no problem retrieving values from the Combo Box
this syntax doesn't seem to work the same way with SELECT
SELECT TAvkastning.Company, TAvkastning.[Forms]![SharperatioForm]!
[Allocation]
FROM TAvkastning
WHERE TAvkastning.Company LIKE ([Forms]![SharperatioForm]![CompanyBox])
thankfull for any help!
Message #2 by tony.scott@n... on Thu, 12 Jul 2001 17:30:59
|
|
Mark,
I think you are getting mixed up between WHERE and SELECT statements.
The SELECT statement is used with record sources (tables, stored
procedures etc) to select one or more columns FROM that source.
The WHERE statement is used to insert some criteria into the statement.
You MUST have a SELECT statement in any recordsource SQL, but you not
need the WHERE statement.
In the example you produced, you have selected column 'Company' from
table (or source object) 'TAvkastning', that being Company is a real
Column of that table.
You then go on to select '[Forms]![SharperatioForm]![Allocation]' from
the same table source. Whereby this is simply a Reference to a control, on
a Form in the Forms collection, and not actually a column of the table.
Finally you have a WHERE statement included, that sets criteria against
the Company column of the table, using the object reference as it's
variable. This is no problem.
So, to conclude, you should only select columns that exist in the source.
I test out my SQL statements by pasting them into a blank Query. If they
return a recordset, then I know they are OK.
HTH
Tony
> Hi,
>
> I wish to use a Combo Box to allow users of an access 97 database to
> select not only a specific row but also which column should be displayed
> by a query.
>
> The WHERE-function has no problem retrieving values from the Combo Box
> this syntax doesn't seem to work the same way with SELECT
>
> SELECT TAvkastning.Company, TAvkastning.[Forms]![SharperatioForm]!
> [Allocation]
> FROM TAvkastning
> WHERE TAvkastning.Company LIKE ([Forms]![SharperatioForm]![CompanyBox])
>
> thankfull for any help!
>
Message #3 by "Julie Hindley" <julie@j...> on Sat, 14 Jul 2001 15:28:54
|
|
> Hi,
>
> I wish to use a Combo Box to allow users of an access 97 database to
> select not only a specific row but also which column should be displayed
> by a query.
>
> The WHERE-function has no problem retrieving values from the Combo Box
> this syntax doesn't seem to work the same way with SELECT
>
> SELECT TAvkastning.Company, TAvkastning.[Forms]![SharperatioForm]!
> [Allocation]
> FROM TAvkastning
> WHERE TAvkastning.Company LIKE ([Forms]![SharperatioForm]![CompanyBox])
>
> thankfull for any help!
>
It sounds like you need to dynamically build the SQL for the query. If
you are displaying the query results on a form, you could set the
recordsource for the form to be the SQL string built when the combo box is
changed. Alternativelly you could modify the SQL of a stored query
through code.
Something along the lnes of:
Dim strSQL As String
strSQL = "SELECT " & cboColumnName & " FROM Test WHERE ...."
Form.RecordSource = strSQL
Message #4 by markusb@m... on Tue, 17 Jul 2001 09:37:02
|
|
Hi Mark,
My wish is to display a specific column from a table by using a Combo Box
to give the user some different alternatives. I was hoping that this would
be possible to do in SQL.
thanks anyway!
/Markus
|
|
 |