PDA

View Full Version : Change Criteria in Query via VBA



ccollins48
11-18-2008, 10:13 AM
I have two print cmd buttons, one to print all records where the CKBox = true and one where I would like to print all records where the CKBox = false.

Is it possible to change a true criteria to false through vba code?

query name: CreditInvoice

Field: CKBox

Table: QryCreditMemoDetails

Current Criteria:True

CreganTur
11-18-2008, 10:25 AM
Is it possible to change a true criteria to false through vba code?

are you referring to changing the value of a record in a table from true to false, or are you referring to changing the criteria for your print buttons via code?

The more detailed information you provide us, the more we can help you.

ccollins48
11-18-2008, 11:05 AM
Basically the Query (CreditInvoices) currently results in printing only the records where the [CKBox] = true.

What I would like to do is code a second print button that will print all records where the [CKBox] = false.

I can accomplish printing only records where [CKBox] = false, if open the CreditInvoices query in design view and change the [CKBox] criteria to false.

My goal is to change that [CKBox] criteria in the CreditInvoices query from true to false when I click the second print button via VBA code and then back to true when I click the first print button.

CreganTur
11-18-2008, 12:12 PM
Ahhh, I see what you mean now- in your Table/query the checkboxes that aren't specified as True show as greyed out- they are neither False nor True.

This is easily remidied- go into your Table in Design view and select your checkbox field. Now, along the bottom of the screen at the General tab. Find the Default Value property and set it to No- this will explicitly set your checkbox to be False- it takes away the ambiguous middle state.

HTH:thumb

OBP
11-19-2008, 08:28 AM
If you actually want to swap between the 2, i.e. True or False (not null) then you can do so without resorting to VBA, you can have an Option Group (Frame) that sets the users choice to True, False or All. You actually include this Frame in the Query Headings using
Forms![Formname]![Framename]

in the new column's Criteria Rows you have 3 Rows, in the first row enter 1, second row enter 2 and third row 3.
In the [CKBox] Column you now enter in the first row (Option 1 True) the value -1.
In the Second Row (Option 2 False) the Value 0.
You leave the third row blank for All records.

You can see this kind of setup in use if you follow the link that I posted here

http://www.vbaexpress.com/forum/showthread.php?t=23599

in post #3