FindFirst on a date/time field? What's wrong here?

FindFirst on a date/time field? What's wrong here?

Post by Eric Kraem » Wed, 10 Apr 1996 04:00:00



vb4-16 on win95

Greetings,

I am trying to use the findfirst method on a table type recordset.
The search field is a date/time field in an access 2.0 mdb

The following code does not find the record, ever.

TestRS.FindFirst "(TestID=#" & Format(pTestDate, "General Date") &
"#)"

I have tried a number of variations of #, ", ' and other punctuation
and formating the ptestdate as a number, no formated etc.

In access It will find the record if in the find dialog box it is
marked as search as formated.

How can I do this in vb?

Thanks,

Eric

 
 
 

FindFirst on a date/time field? What's wrong here?

Post by John Par » Wed, 10 Apr 1996 04:00:00


When I have been using dates and Access in Visual Basic, they
have always been setup as string variables.

Why don't you build the condition in a variable, and then issue
the FINDFIRST on the string.  This way you could put a
breakpoint on the FINDFIRST, and see how the statement looks.

Hope this helps,

JP

 
 
 

FindFirst on a date/time field? What's wrong here?

Post by hhoffic » Fri, 12 Apr 1996 04:00:00


Quote:>The following code does not find the record, ever.
>TestRS.FindFirst "(TestID=#" & Format(pTestDate, "General Date") &
>"#)"
>I have tried a number of variations of #, ", ' and other punctuation
>and formating the ptestdate as a number, no formated etc.

Try using the CDate (CVDate on VB 3.0) function instead of Format!

Kurt Hjortdahl

 
 
 

FindFirst on a date/time field? What's wrong here?

Post by Eric Kraem » Sat, 13 Apr 1996 04:00:00



>When I have been using dates and Access in Visual Basic, they
>have always been setup as string variables.

Can you explain this?

Quote:>Why don't you build the condition in a variable, and then issue
>the FINDFIRST on the string.  This way you could put a
>breakpoint on the FINDFIRST, and see how the statement looks.

The statement looks OK.

When I go to the debug window I get the date from the RS to look the
same as the Criteria.  ie Visually, it looks like it matches.  Here is
the updated code:
----
  Dim ReplaceWhere As String
  ReplaceWhere = "(TransID=#" & TransID & "#)"
  MsgBox ReplaceWhere
  FeedRS.FindFirst ReplaceWhere
----

In access It will find the record if in the find dialog box it is
marked as search as formated, if not checked search as formated, then
I cannot find the match.

I'm lost, as I have tried a number of different variations using the
format function and none have worked.

Can I do something with formating the criteria like this:
ReplaceWhere = "(Format(TransID, ""General Number"") =" &
Format(TransID,""General Number"") & ")"
I have tried but have syntax problems . .

Ideas?

How do others do this?  I'm sure I'm not first to try this . ..

Eric

 
 
 

FindFirst on a date/time field? What's wrong here?

Post by Eric Kraem » Tue, 16 Apr 1996 04:00:00


My first post was not very clear on what I am doing.  Here goes. . .

FeedRS!TransID  General Date (eg 1/1/1995 12:05:00 AM)
TransID         Function Parameter passed as a date.  Also a General Date
FeedRS!TransID  is an access 2.0 field formated as a General Date
---
Public Function ReplaceRecipe(TransID As Date, InvControl As Boolean)
'Finds any occurance of the transaction and replaces
.....
Dim FeedRS as Recordset
Set FeedRS = DB.OpenRecordset("FeedLog")      'The feed log
.....
  Dim ReplaceWhere As String
  ReplaceWhere = "([TransID]=#" & TransID & "#)"
  MsgBox ReplaceWhere
  FeedRS.FindFirst ReplaceWhere
  If FeedRS.NoMatch then
        . . . .. .
  Else
     'Replace
      . .. . .
---

In access, when I open the table and search for a value that I have
copied from a record and pasted into the search box, when I press find
first it cannot find it.  If I check Search as Formated, then it is
found.  I assume that I am running into the same problem in VB.

I understand that Dates are stored as numbers and have tried createing
another field in the query and searching on that.  (I format the
TransID to TargetID: Format("TransID","General Number")  It still
doesn't match.

I always get NoMatch = True

When I go to access or open the forms I can see that there are records
that match.

???
Ideas?

Thanks

Eric

 
 
 

1. Findfirst problem with date/time fields

On a related note:   Now it doesn't Type Mismatch me to death but it still
doesn't work.  It opens it to the first record.  The findfirst fails and
doesn't find the record even though there is a time date field with that
date.  I think the problem is that the field "Date" contains a time and date.
In access it is set up to display the date but the actual contents look like:
"2/20/95 3:14:45 PM"  How do I match on just te date part?

This is the code I am using and it doesn't work.  

Dim All_the_Records As Snapshot
Dim Index as Integer

Set All_the_Records = DB.CreateSnapshot("Select * From [" & Table_Name & "] Order By [Date]")
All_the_Records.FindFirst "Date = #02/20/95#"
'All_the_Records.NoMatch = True at this point even though the date is there

Thanks in advance for any help.

Jerry
--
GCS/E d(++) H s+: g? !p+ !au a- w+ v- C+++ U++ P+ N+++ y?
 E--- W+ !M V -po+ Y !tv b+++ D++ B-- e* u+ h+ f !r n----

2. SQL Client tools install on Windows XP

3. Can't read time from Access 2000 date/time field

4. DDE and FileMaker

5. how to change dates or times in a oracle date time field

6. error with DECIMAL parameter, but FLOAT works.

7. ADO with Access Date/Time field not storing the time, just the date

8. read-only cube

9. Query datetime-field by date when field contains date + time

10. Wrong Date('Today')

11. FindFirst and Date fields

12. Findfirst method for name and date field

13. FindFirst with Date Fields