Problems with DoCmd.ApplyFilter

Samantha

still learning...
Local time
Today, 15:29
Joined
Jul 12, 2012
Messages
187
Hi All,

I seem to be having a difficult time getting my form to filter on opening. I have tired several variations and can seem to get it any help is greatly appreciated. :confused:

I have one form entitled frmProposalDetails on this form there is a field named [Contact] then there is also a button cmdCheckContact. When you press cmdCheckContact it opens frmContactCheck, on this form is the second field to be matched [ContactName]. The following code is attached to frmContactCheck. Both fields being matched are text.

Code:
Private Sub Form_Load()
On Error GoTo Form_Load_Err
    DoCmd.ApplyFilter , "ContactName = '" & tblProposals.Contact & "'"
 
Form_Load_Exit:
    Exit Sub
Form_Load_Err:
    MsgBox Error$
    Resume Form_Load_Exit
End Sub

Thanks!
Samantha
 
Thanks Bob,

I changed the on click event to your code and entered as you suggested although It displays a message box stating Object Required. It does open the correct form and a filter is applied although it displays a blank record.

Note: tblProposals.Contact is the control source of the field I was attempting to match, I was just attempting variations trying to make something work.
 
Okay,

I removed the On Load code, it had not been previously. Now there is no Error Message. It opens the form and navigates to a blank record 1 of 1. When I switch to Design View on the Property Sheet under Filter it states [ContactName]="16" which 16 is equal to the contact so there must be a problem somewhere else as well. Perhaps the combo box settings from the first form are causing the problem. Although the ID is on that form so perhaps just changing the field to ContactID would be easier. Although that field is an Integer, so I would just remove the &Chr(34) right?
 
Oh, I got it, thanks for all your help Bob!

Code:
Private Sub cmdCheckContact_Click()
DoCmd.OpenForm "frmContactCheck", acNormal, , "[ContactID]=" & Me.Contact
End Sub
 

Users who are viewing this thread

Back
Top Bottom