473,396 Members | 1,834 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.

Multiple Values in Checkbox to be stored in one single field

Tinay21
I want to stored multiple data in one field named "Seriousness Criteria" using Checkbox. How is it possible for me to do so?
Thank you!


Attached Images
File Type: png Untitled.png (3.9 KB, 1032 views)
File Type: png Untitled1.png (3.3 KB, 1081 views)
Jun 22 '15 #1
3 2655
zmbd
5,501 Expert Mod 4TB
This sounds like a violation of the Database Normalization and Table Structures practices used in good database design.

+ If you are talking about storing a list of possible values to be used as a checkbox, then the answer is yes and no. However, Yes is very difficult for the novice to implement and can make the future maintenance/upkeep a very difficult proposition as things invariably change.

+ If you are talking about storing the various checked values in the field then the answer is again, yes and no. However, the yes is somewhat difficult for the novice to implement and really should not be done in most cases as this violates the above normalization best practices.

If you can clarify the direction you are going and tell us how much experience you have in Access (or for that fact any) database application design we may be able to guide you in the right direction.
Jun 22 '15 #2
jforbes
1,107 Expert 1GB
I agree with Zmbd that it would be best for you in the long run to break out these fields into separate data elements. The two big reasons for this:
  1. Binding to a Control can be done without code. This means that a Continuous Form can be used to display and edit data. Unbound fields and Continuous Forms don't go together well and if the value of an unbound control changes on a continuous form, it changes for every occurrence of the control on the form.
  2. Reporting and Querying is much easier as you won't have to perform bitwise operations, which aren't bad, but not as clean as other forms of criteria.

If we haven't deterred you yet, then the following is one way to accomplish this.

Place these functions in a Module:
Expand|Select|Wrap|Line Numbers
  1. Public Function getBit(ByRef iValue As Long, ByRef iBit As Integer) As Boolean
  2.     getBit = (iValue And (2 ^ iBit)) > 0
  3. End Function
  4. Public Function setBit(ByRef iValue As Long, ByRef iBit As Integer, ByRef bSet As Boolean) As Long
  5.     ' iValue - Number to use to set (or reset)
  6.     ' iBit - 0 to 30, bit to set or reset in iValue
  7.     ' bSet - True to set the bit, False to Reset the bit
  8.     If bSet Then
  9.         setBit = (iValue Or (2 ^ iBit))
  10.     Else
  11.         setBit = iValue And ((2 ^ iBit) Xor 2147483647)
  12.     End If
  13. End Function
These are the bitwise Getter and Setter used to get and set the bits in the SeriousnessCriteria field.

The following code is an example pulled from a test database that has four checkboxes that are mapped to a single database field:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Check0_AfterUpdate()
  2.     Call updateCheck(Me.Check0.Value, 0)
  3. End Sub
  4.  
  5. Private Sub Check2_AfterUpdate()
  6.     Call updateCheck(Me.Check2.Value, 1)
  7. End Sub
  8.  
  9. Private Sub Check4_AfterUpdate()
  10.     Call updateCheck(Me.Check4.Value, 2)
  11. End Sub
  12.  
  13. Private Sub Check6_AfterUpdate()
  14.     Call updateCheck(Me.Check6.Value, 3)
  15. End Sub
  16.  
  17. Private Sub Form_Current()
  18.     Me.Check0.Value = getBit(Me![Attributes], 0)
  19.     Me.Check2.Value = getBit(Me![Attributes], 1)
  20.     Me.Check4.Value = getBit(Me![Attributes], 2)
  21.     Me.Check6.Value = getBit(Me![Attributes], 3)
  22. End Sub
  23.  
  24. Private Sub updateCheck(ByRef bValue As Boolean, ByRef iBit As Integer)
  25.     Dim lAttributes As Long
  26.     lAttributes = setBit(Me!Attributes, iBit, bValue)
  27.     If lAttributes <> Me!Attributes Then Me!Attributes = lAttributes
  28. End Sub
  29.  
How it works...
  • Form_Current decodes the value to be displayed for each of the Checkboxes and sets the checkboxes accordingly. This is performed whenever the current record changes.
  • updateCheck() is a function that sets or resets a bit in the number that is saved to the database. This is called when a user changes the value of a checkbox.
Jun 22 '15 #3
NeoPa
32,556 Expert Mod 16PB
It may make sense to have this available for reporting purposes, but, as the others have said, storing and maintaining it is a big no-no.

The SQL to include in a query for this would look similar to :
Expand|Select|Wrap|Line Numbers
  1. Mid(IIf([Death],', Death','') & IIf([Hospitalisation],', Hospitalisation/Prolonged','') & ...,3,9999) AS [SeriousnessCriteria]
You can see where I've guessed at your field names. You would need to replace and extend these with entries for each field you wanted to include in the result.
Jun 22 '15 #4

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

Similar topics

3
by: smen | last post by:
hiye, can stored procedure return multiple @output's? thanks for replying...
2
by: palani12kumar | last post by:
Hi..... I've a table that contains the students marks. The fields in the table are: Sno,m1,m2,m3,m4,m5,total,avg,grade. im having ten records in the table in which, i've to update the grade...
0
by: Mervin Harshal | last post by:
I need to know a way to pipe the output of an sql (select )statement to a stored procedure. Eg: The stored procedure is sp_rsch_filters param1,param2,param3 Requirement is to pass param1,param2...
6
by: muhammadrashidmughal | last post by:
I need to know a way to pipe the output of an sql (select )statement to a stored procedure. Eg: The stored procedure is sp_rsch_filters param1,param2,param3 Requirement is to pass param1,param2...
0
by: dan | last post by:
Hi, I have a form that displays record fields. The record has a 'type' field. I'd like to use different controls for one of the fields based on the type. I initially thought of putting all...
4
by: bhappy | last post by:
Hai All, Im creating 2 formula fields in my crystal reports for displaying empname and salary like this, abc 100 xyz 200 pqr 300 in code behind...
4
by: Whizzo | last post by:
Hi all; Here's a record in my table for you: ID AcctNos Balance AcctTypes AcctOwners 20 3456,3457,3458,8766 12000 p,p,p,b John,John,John,Mary I managed to generate it...
0
by: codemaster1 | last post by:
How to show multiple values in crystal report using a single parameter.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.