Results 1 to 11 of 11

Thread: [RESOLVED] Simple problem...I think

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    28

    Resolved [RESOLVED] Simple problem...I think

    All i'm trying to do is retrieve records from the database which match a certain date, but for some reason i keep getting a 'type mismatch' error. I've writen it simply like this to show the syntax i have used.

    VB Code:
    1. temp = "6/12/2006"
    2. GetData ("SELECT * FROM tblcosts WHERE start_date = '" & CDate(temp) & "'")

    Could someone please to me what i'm doing wrong? I suspect its something stupidly simple. I've tried it with and without using 'cdate'

    Cheers

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Simple problem...I think

    Is it access...then use # around the date value or use DateValue function
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    28

    Re: Simple problem...I think

    Quote Originally Posted by ganeshmoorthy
    Is it access...then use # around the date value or use DateValue function
    I tried this and still get the same error.

    VB Code:
    1. temp = "6/12/2006"
    2. GetData ("SELECT * FROM tblcosts WHERE start_date = '" & DateValue(temp) & "'")

    The error is:

    Unable to connect
    data type mismatch in criteria expression


    I know my code used to connect to the database is fine cos if i type

    VB Code:
    1. getdata("SELECT * FROM tblcosts")

    it will display all the records.

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Simple problem...I think

    it should be
    VB Code:
    1. "SELECT * FROM tblcosts WHERE start_date = DateValue ('" & Format(temp,"DD/MM/YYYY") & "')"
    and what does this GetData...what is the data type of Start_date in your database...what database you are using...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    28

    Re: Simple problem...I think

    Getdata is just a procedure which connects to an Access database via ADODB.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Simple problem...I think

    What is the field type into which you are trying to store this date?

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    28

    Re: Simple problem...I think

    in access it is date/time

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Simple problem...I think

    Quote Originally Posted by Rincewind
    in access it is date/time
    Then you will need to encapsulate you date variable with the # signs as ganeshmoorthy pointed out in Post #2. This is something that Access requires.

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Simple problem...I think

    It is.. they are supposed to be used in place of ' , eg:
    VB Code:
    1. GetData ("SELECT * FROM tblcosts WHERE start_date = #" & temp & "#")

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    28

    Re: Simple problem...I think

    Cool cheers guys...you're legends

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