Button to replace toggle filter

vidus

Confused User
Local time
Today, 15:03
Joined
Jun 21, 2009
Messages
117
Hello! We are using a split form, and the staff keeps messing up or clearing their filters and always has to reset it... I would like to place a button on the form that will do away with the need to always redo the toggle filter. A permanent button.

I tried using the button wizard but I assume if the set filter is cleared the button will no longer work? In any case I could not figure that out. The filter we are running is in field [Invoiced], "does not equal Yes"... so that we can hide the jobs that are invoiced (complete) from the datasheet.

How can I create a button that we can keep on the form?
 
approx:
Code:
sub btn_click()
    me.filter = "[Invoiced]=No"
    me.filteron = true
end sub
 
approx:
Code:
sub btn_click()
    me.filter = "[Invoiced]=No"
    me.filteron = true
end sub

:confused: Does nothing.

I is confuse.
 
Try this:
Code:
sub btn_click()
Me.Form.filter = "[Invoiced]=No"
Me.Form.filteron = true
end sub
 
Try this:
Code:
sub btn_click()
Me.Form.filter = "[Invoiced]=No"
Me.Form.filteron = true
end sub

This one works, but on a second click is does not turn the filter off... I would hope I can program this into the same button? Not sure I would want to have a seperate button for this.
 
Code:
sub btn_click()
 
If Me.Form.FilterOn = true then
    Me.Form.filter = ""
    Me.Form.FilterOn = false
    Me!btn.Caption = "Apply Filter"
Else: 
    Me.Form.filter = "[Invoiced]=No"
    Me.Form.FilterOn = true
    Me!btn.Caption = "Remove Filter"
End If
 
End Sub
 
Code:
sub btn_click()
 
If Me.Form.FilterOn = true then
    Me.Form.filter = ""
    Me.Form.FilterOn = false
    Me!btn.Caption = "Apply Filter"
Else: 
    Me.Form.filter = "[Invoiced]=No"
    Me.Form.FilterOn = true
    Me!btn.Caption = "Remove Filter"
End If
 
End Sub

That is excellent. Where do you learn this? I have a lenghy book on access but it does not go into any of this. :) Where can I learn to code from scratch?
 
That is excellent. Where do you learn this? I have a lengthy book on Access but it does not go into any of this. :) Where can I learn to code from scratch?

It is hard at first especially when you don't even have the language to phrase a question clearly. But it comes in time.

It is a learning curve. Much of it is passively infused as each step in understanding is slowly and sometimes painfully taken. You see the patterns in the syntax and it all begins to slowly make sense.

The simple stuff gets easier even though it seems nothing ever works without having to go over and over to iron out the bugs. Then one day you find you can type out a procedure and it works first go. It is a good feeling.

Remember that (virtually) everything you can do in design mode of Access can also be done in VBA. So for example when you see Caption is a property of a Control object you try Controlname.Caption and sure enough it is there. Drop the spaces in properties with two words.

One of the really heartening things is that you can presume that anything can be done and persistence will always win with the help of sites like this. If you want to do something, image how it might be done and go looking for the kind of words you might expect.

The autoprompt in the VBA Editor is very useful. Trawl through its suggestions until you see a likely candidate for the property or method you want. Try it and see. Or press F2 for the Object browser and search. AFIAK every VBA property and method is listed in there.

Don't be afraid to try something. Trial and error reveals what doesn't work and this knowledge can be as enlightening as what does work. Have a scratchpad database to test concepts on and always keep a fairly up to date backup of your real work in case you accidentally discover a command to wipe out something important.;)

Finding the code to do the job is really only the trimming. The foundations are envisioning the constructs you need to achieve the goal. Map out the bones of your complex procedures in comments first and then fill in the meat.

I've never actually studied Access from a book. Google is the developer's friend. It will find postings of similar problems, usually accompanied by the answers and often along with some more of the background information.

Read other peoples problems here. I have stumbled across many new techniques and solutions to problems I hadn't even encountered yet.

Most of all experiment and persist until you achieve what you set out to do. It is a hard road but learning how to program in Access is ultimately really rewarding.

There is no end to challenges if you want to do complicated things. Developers with ten years experience will still tell you they are learning new stuff all the time.
 

Users who are viewing this thread

Back
Top Bottom