A tough problem

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

Hi folks,

I need a urgent help on my query. I have Sales and
tblField tables

Sales table have the following field:

Invoice
Code
Amount
IDate

tblField table have the two fields ID and fName.

ID fName
1 Invoice
2 Code
3 Amount
4 Idate


I created the following query but it didn't work:

SELECT [Sales].[(Select fName from tblField where ID =
[Enter ID])] AS Expr1
FROM Sales;

Could anyone help me to fix the query?

Any help will be appreciated.

Tim.
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You can't do what you're trying to do: create a query that changes the
column (aka field) name depending on the user input. You'll have to use
VBA to change the SQL string. E.g.:

Set up a form that allows the user to select the field name from a
ComboBox (name it cboFieldName: RowSource = "SELECT fName FROM tblField
ORDER BY fName"); and a CommandButton to run the query. The OnClick
event of the CommandButton should be something like this:

Private Sub cmdRunQuery_Click()

dim strSQL as string

strSQL = "SELECT " & Me!cboFieldName & " FROM Sales"

' Use DAO to run the query
CurrentDb.Execute strSQL, dbFailOnError

End Sub

Put in error handling, if you want.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQPSSAoechKqOuFEgEQLZCQCgiXN0cs87FT31EQwZciQu9aEarrMAn2BV
8slQDHYG9jvqffSRr8g38RFT
=I4wp
-----END PGP SIGNATURE-----
 
Back
Top