|
Question : Applying a filter to Main form and SubForm based on InputBox
|
|
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
|
|
Answer : Applying a filter to Main form and SubForm based on InputBox
|
|
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
|
|
|