ms access - Writing Dynamic SQL Statement -
I am very new to Microsoft Access.
I would like to select a column from a table, the value of a parameter (i.e. the column is x, y and z in my table and I have a chosen color parameter The user is set up using the dropdown.
I can choose one / one column using all the selection commands, however, I instead of my parameter selectedcol I would like to use.
After reading around, In order to use the SET and EXEC commands, entering them into the SQL command enters just errors.
Please give me some advice on how I know about implementing a dynamic-SQL query in Access (properly detailed I think I am writing commands in the wrong place at the moment ...) < / P>
First I created an example table in Access.
After this, I have created an example form to query your value. The dropdown is called 'Selective', select a value from the column dropdown selection and press the "Look Value" button.
Here's the "lookup value" Click the button Click on the event. A SQL statement is dynamically created with the column you selected. Column [FieldName] is changed to that it can be referenced by
private sub btnLookup_Click () retarded rsLookup New ADODB.Recordset as string strSQL as string StrSQL = "Select" & amp; Selector Price & amp; "As [FieldName] from Table1 where id = 1" rsLookup.Open strSQL, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly then rsLookup.EOF = false then txtValue.SetFocus txtValue.Text = rsLookup! [FieldName] Finally, rsLookup.Close End Sub When the button is pushed, whatever column will be given the value you selected. For this simple example, I'm always returning data for row 1.
Comments
Post a Comment