Originally posted by da_beano

VB Code:
  1. public function Nnz(Byval varA as variant, ByVal varB as variant) as variant
  2.   nnz=iif(isnull(vara),varb,vara)
  3. end function
  4.  
  5. Private Sub cmdSrch_Click()
  6.  
  7. Dim date1 as date, date2 as date
  8. Dim blnValid as boolean
  9.  
  10. 'On error resume next
  11.  
  12. '---- perform validation on data on form
  13. blnvalid=true
  14. if nnz(Len(txtdate1.text),0)=0 then blnvalid=false
  15. if nnz(Len(txtmonth1.text),0)=0 then blnvalid=false
  16. if nnz(Len(txtyr1.text),0)=0 then blnvalid=false
  17. if nnz(Len(txtdate2.text),0)=0 then blnvalid=false
  18. if nnz(Len(txtmonth2.text),0)=0 then blnvalid=false
  19. if nnz(Len(txtyr2.text),0)=0 then blnvalid=false
  20.  
  21. if not blnvalid then
  22.  msgbox "Data invalid!"
  23.  exit sub
  24. Enf if
  25.  
  26. '---- Process
  27. date1 = CDate(txtDate1 & "/" & txtMonth1 & "/" & txtYr1)
  28. date2 = CDate(txtDate2 & "/" & txtMonth2 & "/" & txtYr2)
  29.  
  30. '---- check dates correct
  31. MsgBox "Flights between " & Format(date1, "dd/mmm/yy") & " and " & Format(date2, "dd/mmm/yy")
  32.  
  33. datFlights.RecordSource = "SELECT * FROM tblFlight WHERE tblFlight.DDate BETWEEN #" & format(date1, "dd mmm yyyy")& "# AND #" & format(date2,"dd mmm yyyy") & "# ORDER BY tblFlight.DDate;"
  34. datFlights.Refresh
  35. End Sub
OK, hmmm your code should look a little like that.

I've added in a validation check for the data entered and changed bits and pieces around. Can you please test and lemme know what happens.

Note : I've added my nnz function above the sub - this should ideally go into a module...

Vince