Results 1 to 9 of 9

Thread: Database writing

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    120

    Database writing

    Hi,

    I am having problems with my vb code finding records in an access 2000 database by date.

    does the date format have to be the same in the data base as the one i a using in my code ie

    my sql is :-
    "SELECT * From LaborDB WHERE Date = #" & strDate & "#"
    the date format in strDate is 2/12/2002

    in the database the date is 02/12/2002 but the above sql returns that it cannot find it.

    I am using a adodb.connection

    Thanks for any help

    Joolz

  2. #2
    Addicted Member PsudoLogical's Avatar
    Join Date
    Dec 2000
    Location
    Upstate N.Y.
    Posts
    144
    Try changing the data type of your date variable to date... as opposed to string.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    120

    Dates

    Hi,

    I tried changing them but I still can not get a match, If I search using other fields it works such as integers so that means it must be the date. any thoughts as this is driving me mad!!!!


    Thanks

    Joolz

  4. #4
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Washington DC
    Posts
    330
    SELECT * From LaborDB WHERE Date = #" & strDate & "#"
    the date format in strDate is 2/12/2002

    change it to


    SELECT * From LaborDB WHERE Date = "& chr(39) & strDate & Chr(39) & ";"

    the date format in strDate is 2/12/2002

    When pasing a SQL statement from code, I have found that using the # sign doesnt work.
    Swoozie
    Somedays you just should not get out of bed.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    120

    Dates

    Hi,

    I have found a daft solution, my computers date is set to
    day/month/year and appears this way in access

    If i search using #day/month/year# if does not find anything


    but

    If i search using #month/day/year# it works, i smell the americans buggering me about.

    Can anyone tell me why this is, a bag of chips to the winner

    Thanks

    Joolz

  6. #6
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    It's just the way Access is designed. Each database is different (to keep you on your toes!).

    One way I've found to overcome the problem is to do this:
    VB Code:
    1. "SELECT * From LaborDB WHERE Date = #" & format(strDate, "dd mmm yyyy") & "#"

    Not elegant, but it seems to do the trick..!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    120

    Dates

    Thanks

    Your the daddy,


    Joolz

  8. #8
    Junior Member
    Join Date
    Oct 2002
    Location
    Belgium
    Posts
    26
    another way :


    "SELECT * From LaborDB WHERE Date = #" & cdate( 2/12/2002 )& "#"


    johan

  9. #9
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    format(dateVar, "dd-mmm-yyyy") is my best friend

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width