Re: trouble with SQL syntax

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"SteveC" <admlcl@xxxxxxxxx> wrote in message
news:1183576019.701371.86200@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

mySQL = "SELECT * From csparts WHERE Model LIKE " & """*" &
cboModel.Text & "*""" AND StartYr >= (SDate) AND EndYr <= (EDate)

the error I get most is variable not defined for the StartYr .

For starters, you would need to concatenate StartYr and EndYr, same as you did
for cboModel.Text. Something like
....cboModel.Text & "*""" AND " & StartYr & " >= (SDate) AND " & EndYr & " <=
(EDate)"

If StartYr and EndYr and SDate and EDate are strings, you will also need the
single quotes around the string values:
....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")

I can't make out whether you are saying that SDate and EDate are string fields
in the database, or just that StartYr and EndYr are string variables. Whatever
it is, you will need to compare similar datatypes: string to string, or date to
date, or number to number.

Format(Now, "YYY") seems odd to me, I get "07185". You say EDate becomes that,
but maybe you mean EndYr does, since EDate is the field in the database. Is
"07185" going to compare well with whatever is in EDate?


.