M
m stroup
I have the following:
frmQryEvents
chkDate txtStartDate "to" txtEndDate
chkAircraft cboAircraft
etc
tblEvents
EventDate
ACFT
etc..
I am using the following to build my SQL string:
Function BuildSQLString(sSQL As String) As Boolean
Dim sSELECT As String
Dim sFROM As String
Dim sWHERE As String
sSELECT = "s.* "
sFROM = "tblEvents s "
If chkDate.Value = -1 Then
If Not IsNull(txtBeginDate) Then
sWHERE = sWHERE & " AND s.EventDate >= " & _
"#" & Format(txtBeginDate, "mm/dd/yyyy") & "#"
End If
If Not IsNull(txtEndDate) Then
sWHERE = sWHERE & " AND s.EventDate <= " & _
"#" & Format(txtEndDate, "mm/dd/yyyy") & "#"
End If
End If
If chkAircraft.Value = -1 Then
sWHERE = sWHERE & " AND s.ACFT = " & Me.cboAircraft
End If
If chkPilot.Value = -1 Then
sWHERE = sWHERE & " AND s.Pilot = " & Me.cboPilot
End If
sSQL = "SELECT " & sSELECT
sSQL = sSQL & "FROM " & sFROM
If sWHERE <> "" Then sSQL = sSQL & "WHERE " & Mid(sWHERE, 6)
BuildSQLString = True
msgbox sSQL
End Function
The sSQL goes into a querydef function, which is working fine.
The sSQL reads:
SELECT s.* FROM tblEvents s WHERE s.EventDate >= #03/01/2008# AND _
s.EventDate <= #03/31/2008# AND s.ACFT = BF1.
This appears to be right. I entered the dates as 03/01/2008 and 3/31/2008
and I selected BF1 from cboAircraft (ACFT is the field name in the table).
What occurs is that instead of "BF1" showing in the design view as criteria,
[BF1] appears and I am prompted for the BF1 entry (as in a parameter query).
Any suggestions would be helpful. Running Access 2003.
frmQryEvents
chkDate txtStartDate "to" txtEndDate
chkAircraft cboAircraft
etc
tblEvents
EventDate
ACFT
etc..
I am using the following to build my SQL string:
Function BuildSQLString(sSQL As String) As Boolean
Dim sSELECT As String
Dim sFROM As String
Dim sWHERE As String
sSELECT = "s.* "
sFROM = "tblEvents s "
If chkDate.Value = -1 Then
If Not IsNull(txtBeginDate) Then
sWHERE = sWHERE & " AND s.EventDate >= " & _
"#" & Format(txtBeginDate, "mm/dd/yyyy") & "#"
End If
If Not IsNull(txtEndDate) Then
sWHERE = sWHERE & " AND s.EventDate <= " & _
"#" & Format(txtEndDate, "mm/dd/yyyy") & "#"
End If
End If
If chkAircraft.Value = -1 Then
sWHERE = sWHERE & " AND s.ACFT = " & Me.cboAircraft
End If
If chkPilot.Value = -1 Then
sWHERE = sWHERE & " AND s.Pilot = " & Me.cboPilot
End If
sSQL = "SELECT " & sSELECT
sSQL = sSQL & "FROM " & sFROM
If sWHERE <> "" Then sSQL = sSQL & "WHERE " & Mid(sWHERE, 6)
BuildSQLString = True
msgbox sSQL
End Function
The sSQL goes into a querydef function, which is working fine.
The sSQL reads:
SELECT s.* FROM tblEvents s WHERE s.EventDate >= #03/01/2008# AND _
s.EventDate <= #03/31/2008# AND s.ACFT = BF1.
This appears to be right. I entered the dates as 03/01/2008 and 3/31/2008
and I selected BF1 from cboAircraft (ACFT is the field name in the table).
What occurs is that instead of "BF1" showing in the design view as criteria,
[BF1] appears and I am prompted for the BF1 entry (as in a parameter query).
Any suggestions would be helpful. Running Access 2003.