SQL error



VB6 and DAO 3.6

I am attempting to permit the user to select 1 of 3 options in the display of database records.

OptSchedule(0) is titled: Schedule to end of year
OptSchedule(1) is titled: Next years schedule
OptSchedule(2) is titled: All records '(this works)

The SQL statement worked before I included the sSchedule variable also.

I get a syntax errors (missing operator) in my WHERE phrase and I cannot find what is wrong.
In the first option, I am attempting to display all records between the present date and the end of
the year - it does not work.
In the second option, I am attempting to display only those records for the next year - 2007 and
beyond - that does not work either.
I always have trouble with dates. What am I doing wrong this time?

Thank you,
Jim Y


Dim sSchedule As String
On Error GoTo terminate

'Setup SQL search schedule statement
If FrmSearch.OptSchedule(0).Value = True Then
sSchedule = "EventDate => #" & Date & "# AND EventDate =< #12/31/" & Format$(Date, "yyyy") &
"# AND "
ElseIf FrmSearch.OptSchedule(1).Value = True Then
sSchedule = "EventDate => #1/1/" & Format$(DateAdd("yyyy", 1, Date), "yyyy") & "# AND "
Else
sSchedule = ""
End If

strSQL = "SELECT LastName, FirstName, ClientID, "
<Snip>
strSQL = strSQL & "Address1, City "
strSQL = strSQL & "FROM tblClient "
strSQL = strSQL & "WHERE " & sSchedule & " LastName LIKE '" & TxtLastName.Text & "*" & "'"
strSQL = strSQL & " ORDER BY LastName, FirstName, "
strSQL = strSQL & "EventDate, PickupTime1, "
strSQL = strSQL & "ClientID"

Set rstClients = FrmClientData.gdbLimo.OpenRecordset(strSQL)

first option result:
SQL = SELECT LastName, FirstName, ClientID, EventDate, PickupTime1, EventType, Vehicles,
NumberOfPassengers, PickUpLoc1, HourlyRate, Hours, AddChg, Deposit, BalanceType, PmtAmt0, PmtAmt1,
PmtAmt2, PmtAmt3, PmtAmt4, PmtAmt5, RateType, Xcharge, PUChour, Address1, City FROM tblClient WHERE
EventDate => #2/13/2006# AND EventDate =< #12/31/2006# AND LastName LIKE '*' ORDER BY LastName,
FirstName, EventDate, PickupTime1, ClientID

second option result:
SQL = SELECT LastName, FirstName, ClientID, EventDate, PickupTime1, EventType, Vehicles,
NumberOfPassengers, PickUpLoc1, HourlyRate, Hours, AddChg, Deposit, BalanceType, PmtAmt0, PmtAmt1,
PmtAmt2, PmtAmt3, PmtAmt4, PmtAmt5, RateType, Xcharge, PUChour, Address1, City FROM tblClient WHERE
EventDate => #1/1/2007# AND LastName LIKE '*' ORDER BY LastName, FirstName, EventDate, PickupTime1,
ClientID

\tThird option result that works and displays all the records
SQL = SELECT LastName, FirstName, ClientID, EventDate, PickupTime1, EventType, Vehicles,
NumberOfPassengers, PickUpLoc1, HourlyRate, Hours, AddChg, Deposit, BalanceType, PmtAmt0, PmtAmt1,
PmtAmt2, PmtAmt3, PmtAmt4, PmtAmt5, RateType, Xcharge, PUChour, Address1, City FROM tblClient WHERE
LastName LIKE '*' ORDER BY LastName, FirstName, EventDate, PickupTime1, ClientID


.



Relevant Pages

  • Adding record into the subform
    ... display the schedule corresponding to the clientID. ... my client add a schedule into this query form as well. ...
    (microsoft.public.access.queries)
  • Re: 10046 trace: latch free then db file seq. read waits
    ... SQL> sta param k_buffers ... must display, then it hangs for about 2 minutes. ...
    (comp.databases.oracle.server)
  • Re: 10046 trace: latch free then db file seq. read waits
    ... SQL> sta param k_buffers ... must display, then it hangs for about 2 minutes. ... I have a script that returns lines looking like a 10046 trace, ... to create if it can an execution plan that favors getting some of the ...
    (comp.databases.oracle.server)
  • Re: Scheduling DTS Packages on 64-bit SQL Server
    ... My understanding is that DTS components are not available for 64-bit SQL ... > I found the following comment on Microsoft's website in regards to scheduling> a DTS package on a 64-bit SQL Server installation. ... do I need> to buy a 32-bit copy of SQL Server to store my packages on to be able to> schedule them? ...
    (microsoft.public.sqlserver.dts)
  • Re: MSHFlexgrid not displaying data from ADO data control
    ... >> MSHflexgrids display any data. ... >> The MSHflexgrids data sources are ADO data controls which are ... >> programmatically assigned a connection string to an SQL 7 Server through ... >> The SQL Server uses windows network authentication to allow access and I ...
    (microsoft.public.vb.general.discussion)