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!

Auto Load Filter On Form Load

Status
Not open for further replies.

Ryath

Technical User
Feb 24, 2002
84
GB
Hi all,

My mind is at a blank, i want the form to automatically filter out the records for ([TBL Base Data].[Unit Type]="Adross") but what do i put into the Form open for the filter to apply when the form is opened?

Thx All Will [hammer]
 
If you ALWAYS want the filter to apply then hard code it into the Form's Record Source as in:-
"SELECT * FROM [TBL Base Data] WHERE [Unit Type]= 'Adross'"

Or
If you want to be able to remove the filter later put
"[TBL Base Data].[Unit Type]= 'Adross'"
in the Filter property and set the Allow Filters to Yes

Or If you only want to apply the filter in certain cases then put the following coad in the On_Load event

If Not IsNull(OpenArgs) Then
Me.Filter = OpenArgs
Me.AllowFilters = True
End If

And in the DoCmd.OpenForm that causes the form to open, set the OpenArgs parameter to "[TBL Base Data].[Unit Type]= 'Adross'"



QED ?


G LS
 
Coool.... thx alot Smudge!!! it works [roll2] Will [hammer]
 
Within the button that opens the form try this:-

in the ON CLICK property put-

Private Sub _<ButtonName>_Click()
On Error GoTo Err_<ButtonName>_Click
Dim strDocName As String
Dim strFilter As String
strDocName = &quot;<FormName>&quot;
strFilter = &quot;([TBL Base Data].[Unit Type]=&quot;Adross&quot;)&quot;
DoCmd.OpenForm stDocName,, strFilter

Exit__<ButtonName>_Click:
Exit Sub
Err___<ButtonName>_Click:
MsgBox Err.Description
Resume Exit_<ButtonName>_Click
End Sub

In other words it's saying 'open the form and use the filter'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top