-----Original Message-----
Just a slight refinement on Gerald's solution.
On the off chance that your application may be used on machines where the
short date format has been set to dd/mm/yyyy, it's important to realize that
dates in SQL MUST be in mm/dd/yyyy format, so use:
rst.Open "SELECT STATS.[Date], STATS.MDPIX from stats WHERE
STATS.[Date] = #" & Format(startdate, "mm/dd/yyyy") & "#"
or, my preference,
rst.Open "SELECT STATS.[Date], STATS.MDPIX from stats WHERE
STATS.[Date] = " & Format(startdate, "\#mm\/dd\/yyyy\#")
(Okay, I'm lying when I say they must be in mm/dd/yyyy. They can actually be
in any unambiguous format. The point is that Access doesn't respect the
regional settings, and dates in dd/mm/yyyy format will ALWAYS be
interpretted as mm/dd/yyyy for days 1-12 of each month.)
--
Doug Steele, Microsoft Access MVP
(No private e-mails, please)
Gerald Stanley said:
2 problem areas are immediately obvious
1. I have noticed that you appear to have named on the
columns 'Date'. This is a reserved word and must be
surrounded by []. It is bad practice to use any reserved
word as a column name and if you have done this I would
advise changing it.
2. The use of the variable startdate should not be included
within the string. Also it should be enclosed in ## as it
is a date. So the statement should look something like
rst.Open "SELECT STATS.Date, STATS.MDPIX from stats WHERE
STATS.Date = #" & startdate & "#;"
Hope That Helps
Gerald Stanley MCSD
-----Original Message-----
The debug print show a value of 1/5/2004.
get an error message "no value given for one or more required
parameters"
Thanks in advance
Sub FindRecord()
Dim rst As ADODB.Recordset
Dim startdate As Date
Set rst = New ADODB.Recordset
startdate = #1/5/2004#
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenStatic
Debug.Print "value of startdate"; startdate
rst.Open "SELECT STATS.Date, STATS.MDPIX from stats WHERE
STATS.Date = startdate ;"
rst.Close
Set rst = Nothing
End Sub
.
.