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, 5 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
-
Cox Communications and Charter Communications to merge
by
not so anon
22 minutes ago -
Help with WD usb driver on Windows 11
by
Tex265
5 hours, 31 minutes ago -
hibernate activation
by
e_belmont
9 hours, 17 minutes ago -
Red Hat Enterprise Linux 10 with AI assistant
by
Alex5723
13 hours, 5 minutes ago -
Windows 11 Insider Preview build 26200.5603 released to DEV
by
joep517
16 hours, 9 minutes ago -
Windows 11 Insider Preview build 26120.4151 (24H2) released to BETA
by
joep517
16 hours, 11 minutes ago -
Fixing Windows 24H2 failed KB5058411 install
by
Alex5723
19 hours, 21 minutes ago -
Out of band for Windows 10
by
Susan Bradley
20 hours, 54 minutes ago -
Giving UniGetUi a test run.
by
RetiredGeek
1 day, 3 hours ago -
Windows 11 Insider Preview Build 26100.4188 (24H2) released to Release Preview
by
joep517
1 day, 11 hours ago -
Microsoft is now putting quantum encryption in Windows builds
by
Alex5723
1 day, 9 hours ago -
Auto Time Zone Adjustment
by
wadeer
1 day, 15 hours ago -
To download Win 11 Pro 23H2 ISO.
by
Eddieloh
1 day, 13 hours ago -
Manage your browsing experience with Edge
by
Mary Branscombe
18 hours, 13 minutes ago -
Fewer vulnerabilities, larger updates
by
Susan Bradley
6 hours, 39 minutes ago -
Hobbies — There’s free software for that!
by
Deanna McElveen
13 hours, 3 minutes ago -
Apps included with macOS
by
Will Fastie
10 hours, 55 minutes ago -
Xfinity home internet
by
MrJimPhelps
7 hours, 42 minutes ago -
Convert PowerPoint presentation to Impress
by
RetiredGeek
1 day, 8 hours ago -
Debian 12.11 released
by
Alex5723
2 days, 13 hours ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
2 days, 16 hours ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
1 day, 20 hours ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
2 hours, 21 minutes ago -
DBOS Advanced Network Analysis
by
Kathy Stevens
3 days, 9 hours ago -
Microsoft Edge Launching Automatically?
by
healeyinpa
3 days ago -
Google Chrome to block admin-level browser launches for better security
by
Alex5723
21 hours, 50 minutes ago -
iPhone SE2 Stolen Device Protection
by
Rick Corbett
3 days, 4 hours ago -
Some advice for managing my wireless internet gateway
by
LHiggins
2 days, 12 hours ago -
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
1 day, 14 hours ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
3 days, 21 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.