View Full Version : Query which accept date from the form and search into the table?
bunty
07-14-2010, 05:35 AM
hi..
how to write a query which accept date from the form and based on that date display the result.
In a form I am selecting a date value through calander.I am working on access 2003 and vba.
thanks
Imdabaum
07-14-2010, 07:29 AM
Sounds like you want a parameter query.
Set parameter xDate Date/Time;
Select * From Table1 Where Date = [xDate]
Or if you are trying to get the date from existing data
Select * From Table1 Where Date = Forms![frmName].dateField
bunty
07-14-2010, 09:38 PM
hi..
I dont know about the parameter query.But problem is like that.
Lut US take example...I am pike up the date from calander and there is condition if date is "<" it will display only the record which is less then the selected date.Like that i have all the condition(<,>,=,<=,>=).
I need to write the query for that but i dont have any idea.
Please help me solve this.
thanks
Imdabaum
07-14-2010, 09:53 PM
Perhaps you could do it on the After_update sub for the date field. So when you click the calendar you get the date entered in the field. This fires the after_update event.
so
set the filter to Filter = Date < DateField
Then turn the filter on.
bunty
07-14-2010, 10:18 PM
Sorry no idea about what u said.can you please tell me the steps how to do that .what query I should write in vba editor .
one more thing is that i have a dropdown from that we are accepting a value either "<","<=","=" etc how to set one conditional operator is default in that dropdown box.
thanks for your help....
Imdabaum
07-15-2010, 08:33 AM
So imagine you have a sample form that follows the format below;
____________________________________________________________
----------------------------TITLE OF FORM--------------------------
lblID txtID lblCompanyAddedOn dteIN
lblCompany txtCompanyName lblCriteriaFilter txtDateFilter
____________________________________________________________
Right click on the field that you have set to be the filter or criteria (in this example txtDateFilter).
Click on the Event Tab and click the [...] button on the row that says, "After Update", select Code. You will be brought to the VBE. There enter the following code.
(based on the example I drew up)
Private Sub txtDateFilter_AfterUpdate()
Me.Filter = "dteIn < " & txtDateFilter
Me.FilterOn = True
End Sub
That should do it.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.