Solved

Applying a filter to Main form and SubForm based on InputBox

Posted on 2006-06-26
2
565 Views
Last Modified: 2007-12-19
I have a main form and a subform in Access.  I would like to apply a filter to both based on an input box.  The input box will prompt for the orderID.  OrderID is a field in both the main and subform.  I have the following but it keeps asking me for Temp.

Thanks.

Private Sub Find_Order_Number_Click()
On Error GoTo Err_Find_Order_Number_Click
Dim Temp As Long
Temp = InputBox("Enter the Order ID", "OrderID")
DoCmd.ApplyFilter , ("OrderID = Temp")
'With Me.tblOrdersDetail_Subform1.Form
'.Filter = "strOrderID"
'.FilterOn = True
'End With
Exit_Find_Order_Number_Click:
    Exit Sub

Err_Find_Order_Number_Click:
    MsgBox err.Description
    Resume Exit_Find_Order_Number_Click
 
End Sub
0
Comment
Question by:solieajm
2 Comments
 
LVL 34

Expert Comment

by:jefftwilley
ID: 16987866
I think I understand what you're trying to do....but there's another way to do this.
Your main form is based on a recordset. this recordset is either a table or a query of some kind. It in turn is linked to your subform using OrderID I'm assuming. By the very nature of subforms, it will limit it's results based on the Linked field on the main form.

That being said, what you need to do with the OrderID you have the user input is to change the underlying recordset for the main form...ie, filter using the OrderID as criteria.
Ex:

Temp = InputBox("Enter the Order ID", "OrderID")
strSQL = "Select * from SomeTable where OrderID =" & Temp
me.main.recordset = strSQL
me.main.requery


You could produce the same results by creating a dropdown combo box on your main form that displays all the OrderID values and lets you select one. this in turn will create a new recordset for the main form using the item you select to filter the results as mentioned above. Part of the problem you're having is moving that entry from your pop-up form back to the main form.
0
 
LVL 10

Accepted Solution

by:
kirenievs earned 250 total points
ID: 16988339
If main and sub are propely linked you do not need to set filter on the subform

Private Sub Find_Order_Number_Click()
On Error GoTo Err_Find_Order_Number_Click

Dim Temp As Long
Temp = InputBox("Enter the Order ID", "OrderID")
With Me
.Filter = "OrderID=" & Temp
.FilterOn = True
End With

Exit_Find_Order_Number_Click:
    Exit Sub

Err_Find_Order_Number_Click:
    MsgBox err.Description
    Resume Exit_Find_Order_Number_Click
 
End Sub

You think you should also should think about how to handle this if the user push Cancel or Ok without any values or with non integer values entered.

If you still need to filter the sub, this might work:

Private Sub Find_Order_Number_Click()
On Error GoTo Err_Find_Order_Number_Click
Dim Temp As Long

Temp = InputBox("Enter the Order ID", "OrderID")

With Me.tblOrdersDetail_Subform1.Form
   .Filter = "OrderID=" & Temp
   .FilterOn = True
End With

Exit_Find_Order_Number_Click:
    Exit Sub

Err_Find_Order_Number_Click:
    MsgBox err.Description
    Resume Exit_Find_Order_Number_Click
 
End Sub
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now