473,396 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Report - want to list boolean fields a very specific way

I have an MS Access table where each record includes, among many other things, 12 boolean fields (checkboxes). I want to build a report which, ideally in ONE text box, displays a string generated as follows:

- First, it displays the contents of a specific text field.
- If *none* of the 12 boolean fields are checked (i.e. none of them are true), then that's it - the string ends at this point.
- If at least one of the boolean fields is checked (true), it gives, in parentheses, a list of short strings corresponding to the true ones.

Examples:
If the text field says "Boogabooga" and none of the boolean fields are checked off, this text box reads:
Boogabooga

If the text field says "Ikiikiptang" and three of the boolean fields are checked off, namely Alpha, Charlie and Foxtrot, this text box reads:
Ikiikiptang (Alpha, Charlie, Foxtrot)

What is the easiest way to accomplish this? I imagine I'd want a query that spits out the parenthetical part, but the exact implementation escapes me.
Sep 22 '13 #1
6 1386
zmbd
5,501 Expert Mod 4TB
Unless you want to go with VBA then you are looking at a series of IIF() conditionals.

A short example and you should be able to go from there...

This example will work as the control source for your text box or as a query, provided the record source for the form or for the query has all of the required Boolean fields.

In case you are not familiar with calculated fields (now I'm going to step this code; however in use, it would be all on a single line)

I'll show you the query version, the control version is basically the same, just use an equal sign instead of the "calcfieldname:"

Expand|Select|Wrap|Line Numbers
  1. z_show_flat:
  2.    "ThisIsStatic" &
  3.    IIF([boolean1],"text1","") &
  4.    IIF([boolean2],"text2","") &
  5.    IIF([boolean3],"text3","") &
  6.    IIF([boolean4],"text4","")
  7. (...)
now these are not "nested" so if [Boolean1], [Boolean3], and [Boolean4] are all true then you get: "ThisIsStaticText1Text3Text4" -->NOTE: I ran the text together because this is how it is shown in the code above... if you need spaces, then you will need to add those inline at the correct point within the text-strings or with additional logic.

You would use the [query]![z_show_flat] as the control source for your textbox

Remember, if you are going to use this directly as the textbox control source then REPLACE the "z_show_flat:" with an equal sign "="

I've not proofed this in my test database; however, I've used similar constructs so I'm fairly certain this should work.
Sep 22 '13 #2
That answers most of my question, and along the lines I was figuring on. However, what I'm not sure of is how to get the parentheses to appear if (and only if) at least one of the boolean fields is true.
Sep 23 '13 #3
zmbd
5,501 Expert Mod 4TB
That's going to be in your logic case....
opening IIF() in the conditional would have each [Boolean1]...[BoileanN] "or"d with each other and the same at the end. Thus if any are true then the opening and closing parentheses. Very ugly.
Maybe my SQL Hero Rabbit has a better SQL approach.
The other way is to code a custom function in VBA to look at the form's recordset for the current record and return the resolved string.
Sep 23 '13 #4
:-(

I'd thought of that but was hoping for something significantly less ugly, like a command I'd overlooked to count the number of "true"s or something. Oh well, back to the salt mines!

Thanks for your help.
Sep 23 '13 #5
zmbd
5,501 Expert Mod 4TB
You might be able to use the Switch()Function for the open and close logic. It would return a null value if none of the conditions are true:
Expand|Select|Wrap|Line Numbers
  1. z_show_flat: 
  2.    "ThisIsStatic" &
  3.    switch([boolean1],"(",[boolean2],"(",(...)) &
  4.    IIF([boolean1],"text1","") & 
  5.    IIF([boolean2],"text2","") & 
  6.    IIF([boolean3],"text3","") & 
  7.    IIF([boolean4],"text4","") 
  8.    (...) 
  9.    switch([boolean1],")",[boolean2],")",(...)) &
  10.  
This would be a little cleaner than the multiple "OR"; however, even with VBA this is going to be somewhat ugly.
Sep 23 '13 #6
ADezii
8,834 Expert 8TB
  1. Let's assume that you have a Table named Table1 with the following Fields:
    Expand|Select|Wrap|Line Numbers
    1. Field1 {TEXT}
    2. A {YES/NO}
    3. B {YES/NO}
    4. C {YES/NO}
    5. D {YES/NO}
    6. E {YES/NO}
    7. F {YES/NO}
    8. G {YES/NO}
    9. H {YES/NO}
    10. I {YES/NO}
    11. J {YES/NO}
  2. Create a Report whose Record Source is Table1 and which consists of only two Text Boxes. One Text Box will be named Field1 and have the same Name for its Control Source.
  3. The other Text Box will be Unbound and its Control Source will be:
    Expand|Select|Wrap|Line Numbers
    1. =fProcessFields([Field1]) 
  4. For each Record, the Value of Field1 will be passed to the fProcessFields() Function wherin all the Logic is self contained. For each Record it will then return the appropriate String.
  5. The Code has been thoroughly tested and is functional. Don't forget to Copy-N-Paste the Function definition to a Standard Code Module. It is posted below:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fProcessFields(strField As String)
    2. Dim MyDB As dao.Database
    3. Dim rst As dao.Recordset
    4. Dim intFldCtr As Integer
    5. Dim blnChecked As Boolean
    6. Dim strBuild As String
    7.  
    8. Set MyDB = CurrentDb
    9. Set rst = MyDB.OpenRecordset("SELECT * FROM Table1 WHERE [Field1] ='" & strField & "'", dbOpenDynaset)
    10.  
    11. 'First, are NONE of the Boolean Fields Checked? Boolean Fields are 2 thru 11
    12. For intFldCtr = 1 To 10
    13.   If rst.Fields(intFldCtr) Then
    14.     blnChecked = True   'At least 1 True
    15.       Exit For
    16.   End If
    17. Next
    18.  
    19. If Not blnChecked Then   '0 Yes/No Fields are Checked, return Text Field only
    20.   fProcessFields = strField
    21. Else
    22.   'At least 1 Yes/No Field Checked, reinterate Yes/No Fields & build String
    23.   For intFldCtr = 1 To 10
    24.     If rst.Fields(intFldCtr) Then
    25.       strBuild = strBuild & rst.Fields(intFldCtr).Name & ", "
    26.     End If
    27.   Next
    28.     'The Final Build (Field Name & " (" & strBuild - Trailing ', ' & ")"
    29.     fProcessFields = strField & " (" & Left$(strBuild, Len(strBuild) - 2) & ")"
    30. End If
    31.  
    32. Set rst = Nothing
    33. End Function
  6. Sample Return Values from fProcessFields():
    Expand|Select|Wrap|Line Numbers
    1. Alpha
    2. Tango (B, D, E, J)
    3. Charlie (A, B, G, H, I, J)
    4. Foxtrot (C, F)
  7. Any questions, please feel free to ask.
Sep 23 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

27
by: John Bailo | last post by:
The recent quarterly earnings report, required by law, issued by the Microsoft Corporation are a harbinger of what is to come. Slowing revenue growth, and declining profits. What we see here is...
0
by: Stephen Haeney via .NET 247 | last post by:
I need an installer to do a couple of very specific things, like check the OS is either Win2K or XP and ensure that the correct service pack ( 4 and 1 ) are installed. I also need to check that IIS,...
3
by: BlackFireNova | last post by:
I am working on an Access 2002 Database. I created a new table and imported some notes data into it from an existing table. Now, when I try to create a List Box, and it displays the list of...
1
by: Stephen B. Ronan | last post by:
In Access 2000, if one goes into design mode for a particular table, one sees a list of fields and field types and down at the bottom one can see field size and other info about each field, one at...
0
by: Corobori | last post by:
I have got plenty of boolean fields in my reports. My user wants to see a checkbox look like pic instead of Yes/No or True/False. How can I achieve this ? jean-luc
3
by: iht | last post by:
Say I have a database with types of car driven by people living in different cities. I made several queries to separate out the database according to city, then made queries to count out numbers...
1
by: muddasirmunir | last post by:
i want list of e-mail address from different countries so can any body guide me how to achive this task . is there any website/utility from which we can extract mail address for e-g i want mail...
0
by: Chetana | last post by:
Hi All, I want list of domains which are registered today ,how many domains deleted,how many are on hold until now on internet. And I want it in asp.net programing. With Regards, Chetana
3
by: mattandlisa3 | last post by:
Is there a way to populate a combo box with a list of fields from a table or query? My purpose in doing this is to allow a user to select a field to search. Also, does anyone have any advice as...
30
by: DanicaDear | last post by:
This is a two part question... I'm after one solution but I've thought of two possible ways to make this work. I want to have a rptCustomer_Inquiry_Report that will list customer information for...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.