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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

command buttons 1

Status
Not open for further replies.

rcreed1

Technical User
May 20, 2004
36
US
I had already done this but I don't know how to do again and I can't decifer my actions...to repeat it.

I have a form that when you open it shows a bunch of command buttons. They are labeled with months and years. ie. JAN 2004, FEB 2004.... I hope that when you click on a button it shows you the form with only the records that meet that month and year that have been entered thus far.

For some reason my Jan button shows that zero records have been entered that meet the criterea of JAN 2004. When i click on the FEB button it is displaying all records in the database. I know I can link the button to a query but I want the results displayed in the form format. I think it to be a problem to how I have the form bound but then again I am lost. A detailed explanation would be appreciated. I hope a queary can be made and is executed when the button is clicked.

Thanks
SFC Reed
 
SFC Reed

Your filters may not be setup correctly - incorrectly applied filter will return zero records.

Your command buttons may run a macro or perhaps visual basic code to apply a filter.

I am assuming your form is open in design mode, and the properties window is open. (View menu -> Properties)

For the command button approach, for the On Click event found on the Event tab of the property window.

For Jan2004 command button
Code:
Dim strWhere as String

strWhere = "Month([YourDateField]) = 1 and Year([YourDateField]) = 2004"

Me.Filter = strWhere
Me.FilterOn = True

Repeat for other periods.

Here is a suggestion...
Hard coding each period is tedious, and means the form has to be edited / customized to work next year.

Instead either use two combo boxes, or one combo box and 12 command buttons (one for each month), or a text box and 12 buttons.

The combo box would select the year (and therefore only find "year" records where data exists). The second combo box, or the 12 command buttons would then be used to retrieve data for the year + month. This type of approach would be more portable.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top