trouble with SQL syntax
- From: SteveC <admlcl@xxxxxxxxx>
- Date: Wed, 04 Jul 2007 12:06:59 -0700
I'm having some trouble getting a search in an access database to work
the way I want.I have a table with several fields and I need to use
three of them for the search filter.
the three fields are Model,StartYr and EndYr.I would like to search a
Model between StartYr and EndYr.On the form I have a combo named
cboModel and a combo array named
combo1(0),thats StartYr and combo1(1) thats EndYr.When I select a year
on the combo1 an integer variable Sdate or Edate is filled in.
the below codes works exactly the way I want, but there are no dates
Private Sub cmdSearch_Click()
Dim mySQL As String
mySQL = "SELECT * From csparts WHERE Model LIKE " & """*" &
cboModel.Text & "*"""
Data1.RecordSource = mySQL
Data1.Refresh
Data1.Recordset.MoveLast
Label5.Caption = "Number of Records
Retrieved : " & Data1.Recordset.RecordCount
Data1.Recordset.MoveFirst
Data1.Refresh
when I change the mySQL to include a date I get errors or else no
results at all
mySQL = "SELECT * From csparts WHERE Model LIKE " & """*" &
cboModel.Text & "*""" AND StartYr >= (SDate) AND EndYr <= (EDate)
the database contents was supplied to me as an excel file and many of
the EndYr entries are "later" so as a result the StartYr and EndYr
fields are defined as String
in the combo1(1).click event if the text is "later" then Edate
becomes format(now,"YYY")
the error I get most is variable not defined for the StartYr .
If anybody point out what I'm doing wrong if would be much
appreciated
Thanks
SteveC
.
- Follow-Ups:
- Re: trouble with SQL syntax
- From: DanS
- Re: trouble with SQL syntax
- From: Phil McFarlane
- Re: trouble with SQL syntax
- From: Bob Butler
- Re: trouble with SQL syntax
- From: Steve Gerrard
- Re: trouble with SQL syntax
- Prev by Date: Re: ntuser.dat >>> when it is used/timestamped
- Next by Date: Re: trouble with SQL syntax
- Previous by thread: Clear
- Next by thread: Re: trouble with SQL syntax
- Index(es):
Relevant Pages
|