write sql using a form

R

Randal

I have several fields that I need to concatenate together based on user
selection in a form. For example, if the user selects Field1 then Field2, I
need a query with

SELECT [Table1]![Field1] & [Table1]![Field2].

If the user selects Field2 then Field1, I need a query with
SELECT [Table1]![Field2] & [Table1]![Field1]

Any help is appreciated.
 
M

Michel Walsh

Hi,


Start with an empty string (zero character) , then add the "fields" as
they are selected (gotFocus):

If SelectionInProgress Then
myString= myString & "FieldName" & ", "
End If


with SelectionInProgress a form-variable, Boolean, that you set to true when
your selection process is active.


At the end, remove the ending ", " and complete the SQL statement:

mySQL = "SELECT " & Left(myString, len(myString)-2) & " FROM
tableName"




Hoping it may help,
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top