Hi


I'm new to Visual basic.

I'm getting an runtime error 424:object not found,When i'm validating between dates in crystal reports.Please correct me where i did wrong..

Private Sub Command1_Click()
Dim f_date As Date
Dim t_date As Date
'From_Date and To_Date Validation

f_date = Trim(Format(DTPicker1.Day, "00")) + "/" + Trim(Format(DTPicker1.Month, "00")) + "/" + Trim(Format(DTPicker1.Year, "00"))
t_date = Trim(Format(DTPicker2.Day, "00")) + "/" + Trim(Format(DTPicker2.Month, "00")) + "/" + Trim(Format(DTPicker2.Year, "00"))

If (Mid(t_date, 4, 2) < Mid(f_date, 4, 2)) Then
MsgBox ("Please check the Date/Month entry")
Exit Sub
End If
If ((Mid(t_date, 4, 2) = Mid(f_date, 4, 2)) And (Mid(t_date, 1, 2) < Mid(f_date, 1, 2))) Then
MsgBox ("Please check the Date/Month entry")
Exit Sub
End If
'End of From_Date and To_Date Validation
CrystalReport1.ReportFileName = "Y:\XYZ\ESJuly\vipf.rpt"
CrystalReport1.RecordSelectionFormula = "{Phase_VIPF.Phase_vipf.date}=> ' " & DTPicker1.Value.Tostring("dd/MM/yyyy") & " '"  and {Phase_VIPF.Phase_VIPF.date}<= ' " & DTPicker2.Value.Tostring("mm/dd/yyyy") & " '"
CrystalReport1.Action = 1
  
End Sub

Edited 6 Years Ago by Nick Evan: Added code-tags

Use your f_Date and t_Date values to get data into the report and not the DatePicker value -

Dim f_date As Date
Dim t_date As Date

f_date = Trim(Format(DTPicker1.Day, "00")) + "/" + Trim(Format(DTPicker1.Month, "00")) + "/" + Trim(Format(DTPicker1.Year, "00"))
t_date = Trim(Format(DTPicker2.Day, "00")) + "/" + Trim(Format(DTPicker2.Month, "00")) + "/" + Trim(Format(DTPicker2.Year, "00"))

'I must confess that I find the above trim etc confusing, because the DTPicker gives you a value once you clicked on it as in -

Text1.Text = DTPicker1.Value
f_Date = Text1.Text

Text2.Text = DTPicker2.Value
t_Date = Text2.Text

'I also would have used only 1 DTPicker and code as follow -

If Text1.Text = vbNullString Then
   Text1.Text = DTPicker1.Value
      Else
   Text2.Text = DTPicker2.Value
End If

'Now to your problem, once you have the declared values, change your code -

CrystalReport1.RecordSelectionFormula = "{Phase_VIPF.Phase_vipf.date}=> ' " & DTPicker1.Value.Tostring("dd/MM/yyyy") & " '" and {Phase_VIPF.Phase_VIPF.date}<= ' " & DTPicker2.Value.Tostring("mm/dd/yyyy") & " '"

TO

CrystalReport1.RecordSelectionFormula = "{Phase_VIPF.Phase_vipf.date}=> DateValue('" & f_Date ("dd/MM/yyyy") & " '" and {Phase_VIPF.Phase_VIPF.date}<= DateValue('" & t_Date ("mm/dd/yyyy") & " '"

This should solve your problem, using the DateValue insert.

>DTPicker1.Value.Tostring

Where "Tostring" is most definitly .NET syntax as VB6.0 does not support such a statement...

and this will raise an error if OP tries to copy/paste such code...

So Shame, SHaME, SHAME, on you... :)

Edited 6 Years Ago by vb5prgrmr: n/a

Oooooh. yes of course. No brain No gain I suppose. Did not even realise what I'm doing.... uh, is it morning yet, coffee or soup?

Sorry M AND vb5, shame on me AGAIN!

This article has been dead for over six months. Start a new discussion instead.