Results 1 to 9 of 9

Thread: [RESOLVED] Problem in monthly records.

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    47

    Resolved [RESOLVED] Problem in monthly records.

    good day! im trying to search records between 2 dates (monthly,weekly). what is wrong with my query/code?

    <code>
    paramDate1 = CDate(DateFrom)
    paramDate2 = CDate(DateTo)

    Set rs = New ADODB.Recordset
    rs.Open "Select * from tblEvents where EventDate between #" & paramDate1 & "# AND #" & paramDate2 & "#", cn, 3, 2
    </code>

    it didn't display monthly record but can display individual date (e.g records dated 12/1/2012 but not 12/1/2012 to 12/31/2012). can u pls give me some advice? or am i doing something wrong?
    thanks guys.

  2. #2
    Hyperactive Member
    Join Date
    Jun 2012
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    333

    Re: Problem in monthly records.

    Hello, Could you please do something like below:
    Code:
    rs.Open "Select * from tblEvents where EventDate between " & "#" & paramDate1 & "#" & " AND " & "#" & paramDate2 & "#", cn, 3, 2

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Problem in monthly records.

    The method shown in post #2 will not be any different.

    What database are you using?

  4. #4
    Hyperactive Member
    Join Date
    Jun 2012
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    333

    Re: Problem in monthly records.

    @ Master Guru DataMiser.. you totally right. If he use DTpicker instead assuming using Access DB, like below because i'm using DTPIcker format mm/dd/yyyy and work fine when i show Data between two Date..

    Code:
    S_Date = DTPicker1.Value
    E_Date = DTPicker2.Value
    
    rs.Open "Select * from tblEvents where EventDate between " & "#" & S_Date & "#" & " AND " & "#" & E_Date & "#", cn, 3, 2

  5. #5
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Problem in monthly records.

    The dates must be formated as follows:
    Access: #yyyy-mm-dd#
    SQL: 'yyyymmdd'
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  6. #6
    gibra
    Guest

    Re: Problem in monthly records.

    As has often been suggested on this and other forums,
    you must use Command with parameters, it avoids all the problems of formatting,
    which as you know can be different depending on the type of database.

    Database - Why should I use Parameters instead of putting values into my SQL string?
    http://www.vbforums.com/showthread.php?t=548787

    See also sample projects on my sign (both ADODB and ADO.NET)

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    47

    Re: Problem in monthly records.

    Hi! Im using Access 2003 as a database. Mr. brss i tried ur query but i still didn't get the correct records. BTW, what f i change the field type in my table from text to date/time? will it help? .

  8. #8
    Hyperactive Member
    Join Date
    Jun 2012
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    333

    Re: Problem in monthly records.

    Well my friend, I'm sorry for not helping you out, I will try my best here. I think your problem related to your saved format in your DB. Have you checked your Date field format, How it's behave? This problem happend to me long time ago when i call Excel report between two date msgbox "No data found" while i have lot of data! try to use DTPicker with field Date/Time. Wish you the best. Thank you

    Edited: DTPicker format will behave as your System date format. And you can customized it for sure.
    Last edited by brss; Dec 9th, 2012 at 11:18 PM.

  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    47

    Re: Problem in monthly records.

    whew! i finally managed to do it. for those who got same problem revise ur queries like this
    Code:
    ("Select * from tblEvents where Eventdate >= #" & firstMonth & "# AND EventDate <= #" & lastMonth & "#")
    just make sure the field in ur DB is a Date/Time formatted as "mm/dd/yyyy". Thanks a lot guys! This forum is really helpful. Cheers!

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