Results 1 to 14 of 14

Thread: Not working correctly

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509

    Not working correctly

    My aim is to select all invoices done by a certain user and done 'today' using system date.

    In my sql statement, when i use the date it returns nothing. When i remove the date section of the statement it works fine BUT selects everything.


    VB Code:
    1. Public Function GetData() As ADODB.Recordset
    2.    Dim strsql As String
    3.    ' Dim r As ADODB.Recordset '
    4.    Dim c As ADODB.Connection
    5.    Dim multipledate
    6.     raised = FrmInvoice.StatusBar1.Panels(3).Text
    7.   multipledate = Date
    8.    Set c = New ADODB.Connection
    9.    c.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False; Data Source=.\Invoice.mdb;"
    10.    c.Open
    11.  
    12.    strsql = "SELECT * from Invoice WHERE RaisedBy = '" & raised & "' AND [Date] = '" & multipledate & "' "
    13.    'strsql = strsql & "WHERE Raisedby = '" & raised & "' "
    14.    'Set rsquery = New ADODB.Recordset
    15.    
    16.    
    17.       rsquery.Open strsql, c, adOpenDynamic, adLockPessimistic
    18.  
    19.    Set GetData = rsquery
    20. End Function

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Not working correctly

    Don't you need to format the date string appropriately for your database?

    e.g. {d '2005-02-02'}
    This world is not my home. I'm just passing through.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509

    Re: Not working correctly

    Thats what i thought originally.

    Then i found a web site that said-

    date = date is same as

    date = format(date, "dd-mm-yyyy")
    I tried it in a textbox and it was right.

    Unless i'm getting american dates and british dates mixed up somewhere.

  4. #4
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Not working correctly

    So, if you do a Debug.Print on strsql what do you get?

    On my PC Date() returns "02/02/2005 ". For SQL Server this should be {d '2005-02-02'}

    VB Code:
    1. "{d '" & Format(Date,"yyyy-mm-dd") & "'}"
    This world is not my home. I'm just passing through.

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Not working correctly

    access data base store dates mm/dd/yy pattern, so you may need to format your date to that pattern to make it match

    rgds pete

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Not working correctly

    have you also seen the replies in the other almost identical thread of yours

    p.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509

    Re: Not working correctly

    Lol, i have tried everything that has already been mentioned apart from the sql part. Thats why i posted it. It seems really wierd. I assumed its something wrong in the sql statement.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509

    Re: Not working correctly

    See i even tried puting the date in directly-

    [Date] = '02/02/2005'

    exactly as it appears in access. It's printing blank invoices. Can't work this one out. seems really wierd.

  9. #9
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Not working correctly

    access data base store dates mm/dd/yy pattern, so you may need to format your date to that pattern to make it match
    I don't have MSAccess on this PC, but I have no reason to disbelieve Pete. Do you need to use "02/02/05" instead of "02/02/2005"?
    This world is not my home. I'm just passing through.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509

    Re: Not working correctly

    I worked it out.

    It's cause i cant use ' ' i have to use # #. they are date delimiters

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Not working correctly

    as replies in the other thread indicated you need to enclose a date in # date #
    characters

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509

    Re: Not working correctly

    Did it? I must of forgot that. I didn't know that sql sees ' ' as text, numbers have nothing and dates have # #.

    So i just put in [Date] = #" & multipledate & "#

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Not working correctly

    if you look at the list of threads in this forum you will see that aprox the 7th one down is also by you with the same title as this thread and i and hack answered you some time ago

    rgds pete

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509

    Re: Not working correctly

    well my bad. Didn't remember it so didn't look at it.

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