View Full Version : find record according to date


deepbreath
06-13-2001, 08:17 AM
i want to search record in a specific period of time, i.e from one date to another date.
by entering the two dates in two text boxes.

D-Fresh
06-13-2001, 08:30 AM
If you want the information on a form then just set up a filter. Create a form with two textboxes(txtBeginDate and txtEndDate) and a command button. On Click of the command button, put the following code

if isnull(me("txtBeginDate")) then
msgbox "You must fill in a beginning Date."
exit sub
elseif isnull(me("txtEndDate")) then
msgbox "You must fill in an end date."
exit sub
else
docmd.openform "Your_Form_Name", , , "[DateField]>=#" & me("txtBeginDate") & "# AND [DateField]<=#" & me("txtEndDate") & "#"
end if

Hope that helps..

Doug

deepbreath
06-14-2001, 05:16 AM
but i want to have a result in a new separate form, which displays the names of the required persons in datasheet view, or listbox will be just fine. and then on clicking any one of the list it will take to the main form for all details

deepbreath
06-24-2001, 01:08 AM
can i use the same code to display the result in a subform already open, which gives you the list of the desired records
and also i base this search on a query

D-Fresh
06-24-2001, 09:51 AM
Yes you can use it for a subform... Just set the filter of the subform to the date criteria or set the recordsource to some SQL statement.

Filter:
Me!SubForm_Name.Form.Filter = "[DateField]>=#" & me("txtBeginDate") & "# AND [DateField]<=#" & me("txtEndDate") & "#"
Me!SubForm_Name.Form.FilterOn = True

SQL:
MySQL = "SELECT * FROM TableOrQueryName WHERE DateField>=#" & me("txtBeginDate") & "# AND DateField<=#" & me("txtEndDate") & "#"
Me!SubForm_Name.Form.recordsource = MySQL

Hope one of these solutions works for you.

Doug

deepbreath
06-30-2001, 08:21 AM
a bit confused. i have two txtboxes for begining date and a end date and a subform below. and a command button, i enter the two dates and press the command button., what to put in click event and what in filter of subform?

D-Fresh
07-02-2001, 04:24 AM
Put this code in the Click event of the button...

Me!SubForm_Name.Form.Filter = "[DateField]>=#" & me("txtBeginDate") & "# AND [DateField]<=#" & me("txtEndDate") & "#"
Me!SubForm_Name.Form.FilterOn = True

And then you don't need anything in the filter of the subform... This code will set the filter after you click the button.

Doug

deepbreath
07-05-2001, 07:09 AM
i don't know what to say, i can not get it right, can you send me a example
deepguru@hotmail.com