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

Need Help with Macro

Status
Not open for further replies.

brendageorge

Programmer
Jun 9, 2011
11
0
0
US
How can I create a macro (or Code) to automate a filtering of a form. I found how to do this by picking advance filters but need to make this easier for users. My form name is Order Details and the field I want to filter is Customer ID. Any help will be appreciated. Thanks
 

Find the OpenForm method in the help files and take a look
at the [blue]Filter[/blue] and [blue]Where Condition[/blue] options.

Randy
 

One way to do it:

Create a combo box on your form - have the bound column be your Customer ID (called CustID). Lets call the combo box: cboPLCustID (PL = picklist)

Create a text box on your form for Customer ID = txtCustID

Add code to the cboPLCustID after_update event:

On Error GoTo ErrorHandler
If Not IsNull(Me!cboPLCustID) Then
DoCmd.ApplyFilter , "CustID=" & Me![cboPLCustID]
End If

cbosurvPick_AfterUpdate_Exit:
Exit Sub

ErrorHandler:
MsgBox Err.Description
Exit Sub
 
How are ya brendageorge . . .

Filtering is a wide an varied subject. No matter what the schema used ... it breaks down into one of two main ideas:
[ol][li]Change the [blue]Where Clause[/blue] of a query used as the recordsource of a form.[/li]
[li]Set the [blue]Filter[/blue] property of a form (the same as a where clause without the where).[/li][/ol]
I find the latter one of the easiest. To get a better understanding ... have a look at [blue]Filter By Form[/blue] ... [blue]MenuBar[/blue] - [blue]Filter[/blue] - [blue]Filter By Form[/blue].

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top