CREATE A QUERY BASED ON THE TICKED CHECK BOX

  • Thread starter Thread starter arni
  • Start date Start date
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
 
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"
 
Back
Top