Resetting a Form

forms_are_nightmares

Registered User.
Local time
Yesterday, 23:17
Joined
Apr 5, 2010
Messages
71
I think this is the problem but I'm not sure...

I have a form with several combo boxes and a button on the form whose code is IF ElseIf statements based on the entries in those combo boxes. When the button is clicked, the form gets filtered. The first click on the button filters properly, however, every subsequent click doesn't work. If I set the values of the combo boxes back to the first values, the form works.

Is there/should I reset the form? It seems that the form is storing those original values somewhere and I can't figure it out.

Any help would be appreciated.
 
What is the button setting?

You can remove a filter by using

Me.Filter = ""
Me.FilterOn = False
 
Here's the code that runs for the search button (it's shortened for this thread):

If Exterior.Value = "Snow Hauling" And Me.statecmbo <> "" And Me.zipcmbo <> "" Then
Me.Filter = "[Vendor State] Like '" & Nz(statecmbo.Value, "") & "*' And [Vendor Zip] Like '" & Nz(zipcmbo.Value, "") & "*' And [Snow Hauling] Like '" & Nz(Yes) & "*'"
Me.FilterOn = True

ElseIf Exterior.Value = "Landscape Installation & Renovation" And Me.statecmbo <> "" And Me.zipcmbo <> "" Then
Me.Filter = "[Vendor State] Like '" & Nz(statecmbo.Value, "") & "*' And [Vendor Zip] Like '" & Nz(zipcmbo.Value, "") & "*' And [Landscape Installation & Renovation] Like '" & Nz(Yes) & "*'"
Me.FilterOn = True
End If


I set the reset button to the code you suggested and that did work to unfilter/reset the form, however, I still can't get any values other than the first ones I used to work
 
Set a breakpoint in your code and make sure that the controls are returning values you think they should.
 
Thanks SOS. I think we're getting somewhere. Still having issues, however, I've been able to isolate some points.

First, I shortened the code and made it explicit. I also put in a statement that if none of the conditions are satisfied, a form would open. When I click on the search button, nothing happens at all, not even the Else statement.

Here's the code:

If Exterior.Value = "Snow Hauling" And Me.statecmbo = "PA" Then
Me.Filter = [Vendor State] = Me.statecmbo
Else
DoCmd.OpenForm "switchboard", acNormal
End IF

[Vendor State] is the text box on the form that should return the value that the combo box (exterior) is set to. The form's data (record sources) are based on 3 linked tables that are linked by a primary key and have referential integrity.

Me.statecmbo is a combo box whose data comes from a state table not linked to any other table in the database.

If you have any insight, I'd appreciate it.
 

Users who are viewing this thread

Back
Top Bottom