Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2009
    Posts
    6

    Unanswered: date parameter in RunSQL help

    Hello, guys,

    I got stuck by passing date parameter into RunSQL command, I have tried many ways, it still does not work. Anyone can help?
    Any help would be appreciated.

    I created a Combo box 'cboDate' and linked it to the 'DateChoice' table, which has only one field: date. I then make following codes:

    Private Sub ChooseDateOK_Click()

    Dim StrSQL1 As String
    StrSQL1 = "SELECT * INTO Temp1 FROM MMMLast " & _
    "WHERE [Date]= " & CDate(Me.cboDate.Value)
    DoCmd****nSQL StrSQL1

    End Sub

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    You need to tell Access that you're passing it a date value, not some variable or arithmetic or something. Like:

    Code:
    Private Sub ChooseDateOK_Click()
    
    Dim StrSQL1 As String
    StrSQL1 = "SELECT * INTO Temp1 FROM MMMLast " & _
    "WHERE [Date] = #" & CDate(Me.cboDate.Value) & "#"
    DoCmd. RunSQL StrSQL1
    
    End Sub
    For more help on this topic, check this out.

    By the way, I would suggest you change the name of your field as it is an Access reserved word (it'll probably cause headaches for you if you don't).

    Cheers!

    EDIT: BTW, remove the space between "DoCmd." and "RunSQL". This forum handles ". ru" funny, as you've seen.
    Last edited by nckdryr; 09-22-09 at 12:28.
    Me.Geek = True

  3. #3
    Join Date
    Sep 2009
    Posts
    6
    Thanks, but I have tried this way, it gave me error message:

    Run-time erro '3075'
    Syntax error in date in query expression '[Date] = #02.09.2009#'


    Because my Combo entry is 02.09.2009 which linked to my date table

    Any other suggestion?


  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    yeah
    format the date as per the US format ( MM/DD/YYYY)
    Access/JET works on dates which are US (and IIRC ISO YYYY/MM/DD)
    that only refers to how the data is presented to the db engine you can esxtract the data in any format your require, and you can chaneg the formatting in any form or report
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Sep 2009
    Posts
    6
    Healdem, thanks a lot! You are right!!!!!!!!

Posting Permissions

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