QuetzalVB
Nov 2nd, 2007, 04:46 PM
I have a form in Access which has a subform nested within it. My users have requested that they be able to search for specific values within the subform, which I know is not a built-in function in Access.
I've created a short VB code attached to a button that is supposed to this by:
1. Prompting the user for the subform value they want to search
2. Running a query with that value
3. Returning the ID number (key) that is in the main form
4. Applying a filter with this ID number
The steps work, except that as Access tries to apply the filter, it throws an error: "The Apply Filter Action was cancelled." The code is below. Anyone have success with this, or have a simpler approach?
Private Sub cmdGp15Query_Click()
On Error GoTo Err_cmdGp15Query_Click
Dim stDocName As String
Dim FilterCrit As Integer
DoCmd.ShowAllRecords
stDocName = "qryFindGp15Unit"
DoCmd.SetWarnings no
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings yes
DoCmd.ApplyFilter , "[ORDER #]=""[tblTempSearchString].[ORDER #]"""
Exit_cmdGp15Query_Click:
Exit Sub
Err_cmdGp15Query_Click:
MsgBox Err.Description
Resume Exit_cmdGp15Query_Click
End Sub
I've tried removing the double quotes (Access doesn't like that) and passing the table value through a variable (also with no success).
I've created a short VB code attached to a button that is supposed to this by:
1. Prompting the user for the subform value they want to search
2. Running a query with that value
3. Returning the ID number (key) that is in the main form
4. Applying a filter with this ID number
The steps work, except that as Access tries to apply the filter, it throws an error: "The Apply Filter Action was cancelled." The code is below. Anyone have success with this, or have a simpler approach?
Private Sub cmdGp15Query_Click()
On Error GoTo Err_cmdGp15Query_Click
Dim stDocName As String
Dim FilterCrit As Integer
DoCmd.ShowAllRecords
stDocName = "qryFindGp15Unit"
DoCmd.SetWarnings no
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings yes
DoCmd.ApplyFilter , "[ORDER #]=""[tblTempSearchString].[ORDER #]"""
Exit_cmdGp15Query_Click:
Exit Sub
Err_cmdGp15Query_Click:
MsgBox Err.Description
Resume Exit_cmdGp15Query_Click
End Sub
I've tried removing the double quotes (Access doesn't like that) and passing the table value through a variable (also with no success).