Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search by Date 2

Status
Not open for further replies.

Kindi

Programmer
Jan 31, 2001
54
GB
I wish the user to enter a date on a form, and click a command button. The command button then finds all records with that date in a certain column, and open the entries found in a certain form, ready to be edited.

How can i do this?

Many Thanks
 
Have the button open a form with a query based on the criterion set by what has been entered in the control on the form, e.g. a text box.

i.e. set up the form you want to display the records on as continuous forms or datasheet view and set up the underlying query with the fields you want to display. In the date field, set a criterion, e.g. if the original form is frmSelectDate and the control that the date is entered into is txtSelectDate, then the criterion in the date field would be something like

'Like [Forms]![frmSelectDate]![txtSelectDate]' (without the quotes).

This should display only those records dates matching the one entered. Alex Middleton
 
Hi Alex

Sorry the code that you have give:

[Forms]![frmSelectDate]![txtSelectDate]

should i but this on the code behind the command button, and if so, do i need the DoCmd command before i enter your code?

Thanks

 
No, put this in the query underlying your second form, i.e. the query in the Record Source property of the second form.

To make it simpler, let's call them Form1 and Form2. On Form1 you will have, for example, a text box (Text1) where the selected date is entered. On Form2 the simplest method is to set it up as datasheet view then set the Record Source property to a new query. To do this, go into the property sheet for the form, click on the Record Source property, then click the little box with dots on it at the right of the dialog.

This will start a new query. Add the table you want the data to come from, then add the fields you want to display to the design grid. This will include the date field you are searching on the first form (Form1).

Under the date field in the design grid, add the code to the 'Criteria' line so that the query looks for records where the date matches the date selected on Form1. As I have changed names, the criteria would look like:

Code:
 'Like [Forms]![Form1]![Text1]'.

Place a command button (Command1) on Form1 and add the following code to its OnClick event:

Docmd.OpenForm "Form2"

This will open Form2 and, if the query has been set up properly, all the records with the date matching the one in Text1 should be displayed, ready for editing. Alex Middleton
 
Hi Alex


Excellent it works, Many thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top