I would like to evaluate a yes/no field on one record with an If…Then…Else Statement. Could someone help me with the procedures and variables for this. The yes/no field is named [fldTax]. The yes/no has been previously selected by the user and is called from a query named [qryTaxable]. If the field has been selected (yes), then I want to run -> DoCmd.OpenQuery “qryRunTaxedReport”. If it has not been selected, then I want to run -> DoCmd.OpenQuery”qryRunNoTaxReport”. Thanks for the help.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
If…Then…Else, Yes/No Procedure (A97SR2)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » If…Then…Else, Yes/No Procedure (A97SR2)
- This topic has 11 replies, 3 voices, and was last updated 22 years, 6 months ago.
Viewing 0 reply threadsAuthorReplies-
WSpatt
AskWoody LoungerDecember 4, 2002 at 6:44 pm #636356When you say the yes/no field is called from a query (qryTaxable), what do you mean by this? Is there only one record returned by this query? How do you access the record with the yes/no in it?
If only one record is returned by qryTaxable then the following should work in VBA code:
Set rs = dbs.OpenRecordset(“qryTaxable”)
If (rs.yes/no fieldname) Then
DoCmd.OpenQuery “qryRunTaxedReport”
Else
DoCmd.OpenQuery”qryRunNoTaxReport”
End IfHTH
Pat -
WSRonM
AskWoody LoungerDecember 4, 2002 at 8:20 pm #636373I tried your VBA code and it came back with – compile error – variable not defined. A further explanation of what I am doing is this: From a one field form the user can enter many different workorder numbers – – when a command button is pressed the workorder numbers are processed one at a time and printed with a Do…Loop. Within this Do…Loop, I want to evaluate whether the workorder is taxable or not taxable (this taxable yes/no field is within each workorder number record has been pre selected for each workorder number). With one query, it will print the workorder with tax and the other query will print it without tax. The Do…Loop works just fine. The method that is used for processing one at a time is: AppendQuery, SELECT TOP1 to a table and then process it – when done, delete that record. I have much difficulty understanding Dim, Set and variables. I have been looking at many error messages; variable not defined, object required, keyword not found, etc., etc. The help information is leaving me confused.
-
WSpatt
AskWoody LoungerDecember 4, 2002 at 8:35 pm #636379For a start you said you wanted to run queries, I now know you mean reports. These queries are the record source of the reports you want to run, right?
Why don’t you put the Yes/No field (let’s call it TaxYesNo) on the form, but NOT enabled and LOCKED so users cannot change it but the VBA code can use it.
Tell me, are there 2 different reports defined or is there 1 report and you just use the different queries as the record source of the report?
If there are 2 different reports, then the following code should be inserted into your DO loop:
If TaxYesNo Then
DoCmd.OpenReport “TaxReportName”,,strCriteria
Else
DoCmd.OpenReport “NoTaxReportName”,,strCriteria
End IfBe sure to substitute your report name in the above code and your fieldname for the YesNo tax field.
Pat -
WSRonM
AskWoody LoungerDecember 4, 2002 at 10:04 pm #636395Actually the two queries, “qryUpdateSummaryTable” & “qryUpdateSummaryTableNoTax” are update queries that send all the different dollar totals for the one workorder to a summary table. This summary table is then used through a query to provide information to one of the 4 subreports of the main report (& not a part of the event procedure). The following is the event procedure with comments.
Private Sub Command3_Click()
Dim Db As Database
Dim rs As Recordset
Set Db = CurrentDb
Set rs = Db.OpenRecordset(“tblBatchWO”)
‘the form, “frmPrintWO” is used to enter the workorder numbers
‘in the “fldWONUM” of the “tblBatchWO”Do
If rs.RecordCount = 0 Then
Exit Do
Else
DoCmd.SetWarnings False
‘take the first wo number and append it
‘to the tblWOnumber table
DoCmd.OpenQuery “qryApnd1toWOnum”‘evaluate taxable or not
DoCmd.OpenQuery “qryPrintOneWO”
‘the “qryPrintOneWO” contains the yes/no field, “fldNotTaxable”
‘the next If…Then…Else should update the Summary tableIf “fldNotTaxable” Then ‘this line does not work. It comes
‘back with a run time error 13 – type mismatch. This is the
‘place where I am totally lost. The two following queries work
‘just fine if I process them manually
DoCmd.OpenQuery “qryUpdateSummaryTable”
DoCmd.Requery
Else
DoCmd.OpenQuery “qryUpdateSummaryTableNoTax”
DoCmd.Requery
End If‘now print a workorder
DoCmd.OpenReport “rptPrintOneWO”, acViewNormal
‘now delete the w.o. number just printed
‘and the corresponding w.o. number in Batch
DoCmd.OpenQuery “qryDel1fromBatchAndWO”
‘now requery the subform
DoCmd.Requery “frmPrintWOsubform”
End If
Loop While rs.RecordCount > 0Set Db = Nothing
Set rs = NothingEnd Sub
-
WSpatt
AskWoody Lounger -
WSRonM
AskWoody LoungerDecember 4, 2002 at 10:44 pm #636413The “qryPrintOneWO” ties together the workorder number with its basic information – registration # – customer number – date started – date finished – labor rate – work description – and if the workorder is taxable. Then via relationship, the registration # gets the appropriate details from the aircraft table – make – model – serial number. Also it is related to the customer table with the customer number to get the company name – address – notes – etc. It is the source for the report that is generated. I was hoping that I could also use it to feed the information to the summary table which is the first subreport on the main report.
-
WSpatt
AskWoody Lounger -
WSRonM
AskWoody LoungerDecember 5, 2002 at 10:30 pm #636739fldNotTaxable is not a control on the form. I am going to try to simplify this whole thing and disregard all previous discussion. As an example, I have just run a query “qryA” that returns one record with two fields: [fldWOnum], the workorder number; and [fldNotTaxable], a yes/no field. What I want to do is: If the [fldNotTaxable] is “yes”, I want to run another query, “qryNoTax”. If the [fldNotTaxable] is “no”, I want to run a query, “qryWithTax”. I am trying to accomplish this with an If…Then…Else within an event procedure. Might there be an easier way to accomplish this?
-
WSpatt
AskWoody LoungerDecember 5, 2002 at 10:42 pm #636742What you could do is:
1. Put an extra column in both queries being the fldNotTaxable field from the query qryA.
For the Criteria of field FldNotTaxable in query qryNoTax you would set it to True.
For the Criteria of field FldNotTaxable in query qryWithTax you would set it to False.
In this way all you have to run in the Event PRocedure is both queries, without any tests.
or
2. You could read query qryA in a recordset and make the decision from that, a la:
Set rs = dbs.OpenRecordSet(“qryA”)
If rs.fldNotTaxable Then
DoCmd.OpenQuery “qryNoTax”
Else
DoCmd.OpenQuery “qryWithTax”
End IfHTH
Pat -
WSRonM
AskWoody Lounger -
WSHansV
AskWoody LoungerDecember 5, 2002 at 6:25 am #636484You write[indent]
If “fldNotTaxable” Then ‘this line does not work.
[/indent]You should use the actual field name without quotes; if the actual field name contains spaces, it should be enclosed in square brackets [ and ]. So if your field is literally named fldNotTaxable, you should use
If fldNotTaxable Then
If the field is named Not Taxable, you should use
If [Not Taxable] Then
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Very Quarrelsome Taskbar!
by
CWBillow
2 hours, 10 minutes ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
4 hours, 55 minutes ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
6 hours, 13 minutes ago -
Is your battery draining?
by
Susan Bradley
1 hour, 41 minutes ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
8 hours, 10 minutes ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
8 hours, 46 minutes ago -
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
12 hours, 1 minute ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
2 hours, 44 minutes ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
5 hours, 15 minutes ago -
National scam day
by
Susan Bradley
8 hours, 11 minutes ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
5 hours, 26 minutes ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
1 day, 9 hours ago -
Tools to support internet discussions
by
Kathy Stevens
1 day, 16 hours ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
1 day ago -
AI is good sometimes
by
Susan Bradley
1 day, 17 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
1 day, 7 hours ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
2 days, 17 hours ago -
June KB5060842 update broke DHCP server service
by
Alex5723
2 days, 15 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
2 days, 19 hours ago -
Excessive security alerts
by
WSSebastian42
1 day, 10 hours ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
3 days, 5 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
2 hours, 36 minutes ago -
Seconds are back in Windows 10!
by
Susan Bradley
2 days, 16 hours ago -
WebBrowserPassView — Take inventory of your stored passwords
by
Deanna McElveen
1 day, 10 hours ago -
OS news from WWDC 2025
by
Will Fastie
20 hours, 14 minutes ago -
Need help with graphics…
by
WSBatBytes
2 days ago -
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
3 days, 20 hours ago -
Totally remove or disable BitLocker
by
CWBillow
2 days, 19 hours ago -
Windows 10 gets 6 years of ESU?
by
n0ads
2 days, 23 hours ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
4 days, 7 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.