CREATE A QUERY BASED ON THE TICKED CHECK BOX

A

arni

Help.

Is there a way of coding a SELECT query that will have its
fields based on the selected check box? Example, I have 3
check boxes
FIRSTNAME
LASTNAME
AGE
I ticked firstname and age. I want a select query that
contains these two as fields.

Is this possible? How?



Many thanks,
arni
 
V

Van T. Dinh

You need to construct the SQL String by code. Something like:

****Untested air-code***
Dim strSQL As String

If (Me.chkFN = False) AND (Me.chkLN = False) AND _
(Me.chkAge = False) Then
MsgBox "You must select at least one Field."

Else
strSQL = "SELECT "
If (Me.chkFN = True) Then
strSQL = strSQL & "[FirstName], "
End If

If (Me.chkLN = True) Then
strSQL = strSQL & "[LastName], "
End If

If (Me.chkAge = True) Then
strSQL = strSQL & "[Age], "
End If

strSQL = Left(strSQL, Len(strSQL) - 2) & " FROM YourTable"
End If
****

The strSQL will have the SQL String you need. Something like (chkFN and
chkAge ticked):

"SELECT [FirstName], [Age] FROM YourTable"
 

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