
Date Criteria In VB Recordsource? HOW!
Quote:
>data1.recordsource = "select * from transactions where inv_date >
>31/12/95"
>I get no errors or anything, it just doesnt't find any records, or it
>finds all of them. I have tried putting the date in single quotes,
>dd/mm/yy, yy/mm/dd, mm/dd/yy format, but nothing seems to work. I must
>be failing somewhere in a very simple way. PLEASE HELP ME!!!
Dates must be enclosed between "#" characters.
I hope that the following code will help you.
Sub CmdSeleziona_Click ()
Dim SQLText, Date1, Date2 As String
'If date is in the dd-mm-yy,
' I get an error when FrmPatenti.DtAnag.Refresh,
'so I have to change it.
Date1 = Format$(MkeDal.Text, "mm-dd-yy")
Date2 = Format$(MkeAl.Text, "mm-dd-yy")
'MkeDal and MkeAl are contents of MaskEdit controls
SQLText = "SELECT * FROM PATENTI WHERE (DAT_SCAD BETWEEN #"
SQLText = SQLText & Date1
SQLText = SQLText & "# AND #"
SQLText = SQLText & Date2
SQLText = SQLText & "#) ORDER BY COGN, NOM "
' FrmPatenti is another form, DtAnag is a data control
FrmPatenti.DtAnag.RecordSource = SQLText
'Activate, VERY IMPORTANT or you will never see any change
FrmPatenti.DtAnag.Refresh
Unload Me
End Sub
Giuseppe Girardelli