Results 1 to 8 of 8

Thread: Anything wrong here[Resolved]

  1. #1

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189

    Resolved Anything wrong here[Resolved]

    Hallo guys
    i'm producing reports from a table and i get a syntax error. the code is below. any ideas what cud be wrong?


    VB Code:
    1. Private Sub Command1_Click()
    2. Dim rs As New ADODB.Recordset
    3.  
    4.     Opencon
    5.     rsrequests.Close
    6.     rsrequests.Open "SELECT * FROM Requests WHERE((DateReq) Between # " & DTPicker1.Value & "# AND #" & DTPicker2.Value & "#)ORDER BY Sort DESC", Cn, adOpenStatic, adLockReadOnly
    7.    
    8.     Set DataReport1.DataSource = rsrequests
    9.     DataReport1.Show
    10.    
    11.     Set rsrequests = Nothing
    Last edited by Paradox; Nov 10th, 2004 at 12:06 AM.
    Peny wise pound Foolish

  2. #2
    Lively Member
    Join Date
    Jan 2003
    Posts
    79
    Hello Paradox,
    Ok, first thing that leaps out is (and I suspect that this is down to the way that code has been pasted in) that you have a dim statement on the same line as your Sub declaration.
    Apart from that I don't think you need to have the "#" characters in the statement, if you are using strings you would need to qualify them with single quotes but if you are passing numbers they don't usually need qualifying.
    Also I'm not sure about the brackets around "DateReq", these might need to be square brackets [].

    Hope this helps,

    Dave.

  3. #3
    Fanatic Member
    Join Date
    Sep 2004
    Location
    Jakarta, Indonesia
    Posts
    818
    or try using [] bracket for Requests, sort

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL,
    Kill Database Processes

  4. #4

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189
    Sorry for the paste, i changed it to the below code, no syntax error now but aint gettin the records. am i going wrong somewhere?

    Thanks


    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.     Opencon
    4.     rsrequests.Close
    5.     rsrequests.Open "SELECT * FROM Requests WHERE((DateReq) Between  " & DTPicker1.Value & " AND " & DTPicker2.Value & ")", Cn, adOpenStatic, adLockReadOnly
    6.    
    7.     Set DataReport1.DataSource = rsrequests
    8.     DataReport1.Show
    9.    
    10.     Set rsrequests = Nothing
    Peny wise pound Foolish

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    try this:
    VB Code:
    1. rsrequests.Open "SELECT * FROM Requests WHERE((DateReq) Between [b]'[/b]" & DTPicker1.Value & "[b]'[/b] AND [b]'[/b]" & DTPicker2.Value & "[b]'[/b])", Cn, adOpenStatic, adLockReadOnly

  6. #6

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189
    Am now gettin this error message. what wrong

    ( The conversion of a char datatype to a datetime datatype resulted in an out of range datetime value).

    What am i not doing. The Datereq field is a Datetime datatype.
    Peny wise pound Foolish

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    the database doesnt understand the value of DTPicker1.Value and DTPicker2.Value so change them into a different format, eg:


    rsrequests.Open "SELECT * FROM Requests WHERE((DateReq) Between '" & Format(DTPicker1.Value, "dd mmm yyyy") & "' AND '" & Format(DTPicker2.Value, "dd mmm yyyy") & "')", Cn, adOpenStatic, adLockReadOnly

  8. #8

    Thread Starter
    Addicted Member Paradox's Avatar
    Join Date
    Sep 2004
    Location
    Nairobi
    Posts
    189
    Thanks, its resolved the err.
    Peny wise pound Foolish

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