Query by checkbox value (1 Viewer)

dzelmej

Jacobs
Local time
Today, 07:58
Joined
Mar 19, 2007
Messages
16
Hi, Im trying to build query that filters my recors by checkbox value in form.
I have field id_reason with numeric values, my idea is that when checkbox1 = 1, id_reason is filtred by value 11, when checkbox1 = 0, id_reason <> 11.

i tryed this formula as criteria in design grid:
IIf([forms]![form1]![check1]=1;[id_reason]=11;[id_reason]<>11)
but IIF is not operator, so it doesnt work...

Can anyone help with this one? :cool:

tnx
 
Last edited:

macca the hacke

Macca the Hacca
Local time
Today, 07:58
Joined
Dec 1, 2005
Messages
221
Why don't you add an event procedure to the on open of the form:

*****
if me.check1 = true then
docmd.applyfilter,"id reason = '11'"
else
docmd.applyfilter,"id reason <> '11'"
end if

*****
 

dzelmej

Jacobs
Local time
Today, 07:58
Joined
Mar 19, 2007
Messages
16
Im not good with vba, I understund where I must enter that code, but how can I point that ApplyFilter to my query (form1_query)...
 

macca the hacke

Macca the Hacca
Local time
Today, 07:58
Joined
Dec 1, 2005
Messages
221
? don't understand your question.
Go to the form you wish to apply the filter to and that has the checkbox. Open in design view. Go to properties > event tab. Using the drop down box on the right of on open choose event procedure, and then click the ... next to the drop down box.
Copy sample code I gave you into there (making any amendments to names as necessary).
 

dzelmej

Jacobs
Local time
Today, 07:58
Joined
Mar 19, 2007
Messages
16
Im getting error message.
In my case I want to apply filter to query (named form1_query), not to form.
I have form1 with check1 and form1_query with field id_reason, so I think that query name should show up somewhere in code ??
 

macca the hacke

Macca the Hacca
Local time
Today, 07:58
Joined
Dec 1, 2005
Messages
221
why do you want the query filtered? If it is to display information to users, then you would have a form displaying the information, and you would filter the form as above (although would need to reference the check box from the other form)
 

dzelmej

Jacobs
Local time
Today, 07:58
Joined
Mar 19, 2007
Messages
16
([id_reason]=11 And [forms]![form1]![check1]=-1)) OR ([id_reason]<>11 And ([forms]![form1]![check1]=0))

this is what I figured out, and it is simple and it works...
 
Last edited:

jai kushwaha

Registered User.
Local time
Today, 12:28
Joined
Nov 1, 2015
Messages
61
I want to make a form in ms access in which if i checked a check box than it value become an hour and it multiply by next field. My mean is if i check the box thats mean it will ask for next field value and if i will put 2 it will multiply with it and give me a value 4, so my question is how to set the value of check box is equal to 2. So that it will automatic multiply in order to give value 4 when i check the box.
 

Users who are viewing this thread

Top Bottom