dcsimg
Results 1 to 4 of 4

Thread: From date & to date is not Searching properly In MSHFlexgrid1

  1. #1

    Thread Starter
    Registered User
    Join Date
    May 2020
    Posts
    1

    From date & to date is not Searching properly In MSHFlexgrid1

    The problem is when I search for the data i.e people{Shubhankar Haldar} within specific date {[1/5/2020] & [18/5/2020]} as in attached picture, the output date which comes is not within specified date.Also some of the dates that falls under the the specified date are missing.

    Code:
    Private Sub search2_Click()
    Set rs_pay = New ADODB.Recordset
    Set adv_pay = New ADODB.Recordset
    rs_pay.Open "Select sum(advalue) from (select ename,date1,advalue from advanceentry where date1>= # " & Format$(Me.DTPicker1.Value, "dd/MM/yyyy") & " # and date1<= # " & Format$(Me.DTPicker2.Value, "dd/MM/yyyy") & " # and ename='" & L_ename.Text & "')", cd_pay, adOpenStatic, adLockOptimistic
    
    
    adv_pay.Open " select ename,date1,advalue,date2 from advanceentry where date1>= # " & Format$(Me.DTPicker1.Value, "dd/mm/yyyy") & " # and date1<= # " & Format$(Me.DTPicker2.Value, "dd/mm/yyyy") & " # and ename='" & L_ename.Text & "' order by date2", cd_pay, adOpenStatic, adLockOptimistic
    If adv_pay.EOF Then
        MsgBox ("NO RCORDS FOUND FOR SELECTED DATE!")
        Else
    Set MSHFlexGrid2.DataSource = adv_pay
    If IsNull(rs_pay(0)) Then
        T_prday.Text = ""
        Else
        T_prday.Text = rs_pay(0)
        
        Me.cmd_print.Enabled = True
        End If
        End If
    End Sub
    Attached Images Attached Images   
    Attached Files Attached Files

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,406

    Re: From date & to date is not Searching properly In MSHFlexgrid1

    Good morning, Shub...

    1-WELCOME TO THE FORUM.

    2-I am not going to look at your project any further (right now, that is). I downloaded it and (after a couple of changes) attempted to run it. I noticed right off that you did not have "Option Explicit" at the top of either form. When I added it, it immediately started flagging undimmed variables. Please add "Option Explicit" to both forms, fix the 'errors', and then repost. Then I will look at it.

    3-Why do you have two identical dates (date1 and date2) in your database (even though both are of different formats!)?

    Sam
    Sam I am (as well as Confused at times).

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,852

    Re: From date & to date is not Searching properly In MSHFlexgrid1

    if it is an access database the date should be in the format mm/dd/yyyy, regardless of your local date format
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,406

    Re: From date & to date is not Searching properly In MSHFlexgrid1

    Yeh, he/she? says it is an Access DB...not sure where OP is coming from here.

    But, willing to help if OP provides better description and OPTION EXPLICIT ON in his/her project.

    :-)
    Sam I am (as well as Confused at times).

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width