FindFirst

  • Thread starter Thread starter BrunoKP
  • Start date Start date
B

BrunoKP

In the FindFirst-line I get the message: "The datatypes are not alike in the
search string", Soegnehelligdag is defined as date/time typetye in the table
tblSHD.
Dim strSearch As String
Dim SHD As Date
SHD = Me.txtDato.Value
Set dbsCurrent = CurrentDb()
Set RecSetSHD = dbsCurrent.OpenRecordset("tblSHD", dbOpenDynaset)
strSearch = "(Soegnehelligdag = 'SHD')"
RecSetSHD.FindFirst strSearch
RecSetSHD.Close
dbsCurrent.Close
 
If Soegnehelligdag is a date/time data type, why are you searching for SHD?
That's not a date/time value.

Date/Time fields can only hold date/time values, or Null. To search for a
specific Date/Time, you must delimit the value with # characters, and you
must use a format Access will recognize (it does not respect the Short Date
format set through Regional Settings. Even if you've chosen dd/mm/yyyy as
your format, 01/07/2008 will ALWAYS be treated as 07 Jan, 2008, rather than
01 Jul, 2008) Note, too, that if your date/time field includes a time value
in addition to the date value, you either need to eliminate that time value
from the comparison:

strSearch = "DateValue(Soegnehelligdag) = #2008-01-07#"

or (better)

strSearch = "Soegnehelligdag Between #2008-01-07# And #2008-01-08#"
 
Hi BrunoKP,

with the strsearch you wrote you search for a string in a date field.
the correct strsearch is:
strSearch = "(Soegnehelligdag = #" & SHD & "#")"

the hash mark (#) is to delimitate a date

HTH Paolo
 
In the first post there's a little typo.
The correct strsearch is:

strSearch = "(Soegnehelligdag = #" & SHD & "#)"

Sorry
 
Thank you Paolo
I was just looking for the compiler error :-)
It works fine now, and I have added test of match with "If RecSetSHD.NoMatch
Then"
Bruno


"Paolo" skrev:
 
As I pointed out, the format of the date is important. Since you don't have
control over what Short Date format your users have chosen, it's far safer
to use

strSearch = "Soegnehelligdag = " & Format(SHD, "\#yyyy\-mm\-dd\#")
 
Thankyou for your concern, I will take that in consideration.
Bruno

"Douglas J. Steele" skrev:
 
Back
Top