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, 4 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
-
Washington State lab testing provider exposed health data of 1.6 million people
by
Nibbled To Death By Ducks
3 hours, 27 minutes ago -
WinRE KB5057589 fake out
by
Susan Bradley
3 minutes ago -
The April 2025 Windows RE update might show as unsuccessful in Windows Update
by
Susan Bradley
9 hours, 38 minutes ago -
Firefox 137
by
Charlie
12 hours, 22 minutes ago -
Whisky, a popular Wine frontend for Mac gamers, is no more
by
Alex5723
15 hours, 50 minutes ago -
Windows 11 Insider Preview build 26120.3863 (24H2) released to BETA
by
joep517
16 hours, 2 minutes ago -
Windows 11 Insider Preview build 26200.5551 released to DEV
by
joep517
16 hours, 5 minutes ago -
New Windows 11 PC setup — can I start over in the middle to set up a local id?
by
ctRanger
9 hours, 10 minutes ago -
Windows 11 Insider Preview Build 26100.3902 (24H2) released to Release Preview
by
joep517
19 hours, 36 minutes ago -
Oracle kinda-sorta tells customers it was pwned
by
Nibbled To Death By Ducks
1 day, 1 hour ago -
Global data centers (AI) are driving a big increase in electricity demand
by
Kathy Stevens
1 day, 11 hours ago -
Office apps read-only for family members
by
b
1 day, 14 hours ago -
Defunct domain for Microsoft account
by
CWBillow
1 day, 11 hours ago -
24H2??
by
CWBillow
1 day, 1 hour ago -
W11 23H2 April Updates threw ‘class not registered’
by
WindowsPersister
19 hours, 52 minutes ago -
Master patch listing for April 8th, 2025
by
Susan Bradley
19 minutes ago -
TotalAV safety warning popup
by
Theodore Nicholson
10 hours, 53 minutes ago -
two pages side by side land scape
by
marc
3 days, 12 hours ago -
Deleting obsolete OneNote notebooks
by
afillat
3 days, 14 hours ago -
Word/Outlook 2024 vs Dragon Professional 16
by
Kathy Stevens
2 days, 17 hours ago -
Security Essentials or Defender?
by
MalcolmP
2 days, 20 hours ago -
April 2025 updates out
by
Susan Bradley
37 minutes ago -
Framework to stop selling some PCs in the US due to new tariffs
by
Alex5723
2 days, 13 hours ago -
WARNING about Nvidia driver version 572.83 and 4000/5000 series cards
by
Bob99
2 days, 3 hours ago -
Creating an Index in Word 365
by
CWBillow
3 days, 6 hours ago -
Coming at Word 365 and Table of Contents
by
CWBillow
1 day, 18 hours ago -
Windows 11 Insider Preview Build 22635.5170 (23H2) released to BETA
by
joep517
4 days, 9 hours ago -
Has the Microsoft Account Sharing Problem Been Fixed?
by
jknauth
4 days, 12 hours ago -
W11 24H2 – Susan Bradley
by
G Pickerell
4 days, 14 hours ago -
7 tips to get the most out of Windows 11
by
Alex5723
4 days, 12 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.