473,508 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make a bound checkbox remain checked for new records

5 New Member
I'm trying to do something I thought would be simple enough even for me, but I'm stuck. I have a checkbox on a form bound to a yes/no column in a table.

I want the user to be able to check the box and have it remained checked as they enter new records, thus saving the tables field as YES for as many records as they wish until they uncheck it. Then when they uncheck it, have it remain unchecked as they create new records, etc...

Eventually I'm going to create either a toggle or command button that does the checking of teh check box for them and probably hide the Check Box control, but that part I can figure out. It's getting it to stay checked or unchecked for each new record until toggled back that's throwing me.
I feel really dumb even asking this question but I'm stumped. I know that an unbound checkbox kind of does what I want, but then how to get it to store the Yes/No answers where I want it to I don't know how to do either. Uhgg I'm so confused. Thanks in advance for your help.
Mar 14 '11 #1
8 4073
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Hi and welcome to Bytes

What you want to do is "simply" modify the default value of your checkbox. Add code to the checkbox' Click Event as such:
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkBox_Click()
  2.     Me.chkBox.DefaultValue = Me.chkBox
  3. End Sub
Mar 14 '11 #2
Rabbit
12,516 Recognized Expert Moderator MVP
In the after update event of the checkbox, you'll want to change the default of the checkbox to what it was just changed to.
Mar 14 '11 #3
NeoPa
32,557 Recognized Expert Moderator MVP
This is a bit complex to follow, so I'll lay it out as clearly as I can. First let me say that the other two answers are clearly correct.

You need to start off with two checkboxes on your form. One for the bound field of your table. The other to indicate, and allow the operator to change, the value that should be treated as the default going forwards. Let's call them chkBound and chkUnbound for now.

You explanation isn't entirely clear, so I'll assume you want to start a session with the default set to True. If this is not the case then please disabuse me. This value (True) should be set as the .DefaultValue in the design of the form for both controls.

Whenever the operator changes the value in chkUnbound, the .DefaultValue of chkBound should be changed to reflect the new value (of chkUnbound).
Mar 14 '11 #4
Jim Monica
5 New Member
Thank You everyone for your replies. I went with the first method as that seemed to be the simplest and with my limited brain power and knowledge, simple is good. Now my next task is to make a toggle button (I think) that allows the user to toggle the checkbox on/off or checked and unchecked. I know I could just use the checkbox for that, but my boss is insisting it be a button because it's also going to change the background of the form or give some other indicator to let the user know they are in the mode where the check box is checked. The ChkBox is there so that when the user is entering inventory items, the items are flagged as consignment items (if checked) and they will usually enter these items in a row in groups of about 50-100 which is why I needed the checkbox to stay checked until they uncheck it. Now I need to somehow Clearly tell the user they are in "Consignment Mode" thus telling them that all of the items they are entering are being flagged as consignment until they hit the button again and go back to "normal" mode. So that's what you guys (or gals) just helped me with and I REALLY appreciate it. Now to google Toggle button. Thank You again everyone!
Mar 15 '11 #5
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
I have tried to keep this simple:
Basicly I have added a togglebutton togBtn and when its clicked it changes the caption on the button, and colours the detail area of the form. (Just for example, you could do other things).

The only "complicated" part is that I have added to the forms Current Event to only colour those records that are new (I.e. dont show the red consignment mode for existing records)

Here is the code: (If this is a continues form you are using, then note that colouring the detail area is not the best approach to use, since it will colour all the records detail area, but you could colour the header area instead.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     If Me.NewRecord And Me.chBox.DefaultValue Then
  3.         Me.Detail.BackColor = vbRed
  4.     Else
  5.         Me.Detail.BackColor = vbCyan
  6.     End If
  7. End Sub
  8.  
  9. Private Sub togBtn_Click()
  10.     'Change default value
  11.         Me.chBox.DefaultValue = Not Me.chBox.DefaultValue
  12.  
  13.     'Change caption on toggle button
  14.         If Me.chBox.DefaultValue Then
  15.             Me.togBtn.Caption = "Consignment Mode"
  16.             Else
  17.             Me.togBtn.Caption = "Other Mode"
  18.         End If
  19.  
  20.     'If this is a newrecord and default is true, color it
  21.         If Me.NewRecord And Me.chBox.DefaultValue Then
  22.             Me.Detail.BackColor = vbRed
  23.         Else
  24.             Me.Detail.BackColor = vbCyan
  25.         End If
  26. End Sub
Mar 15 '11 #6
Jim Monica
5 New Member
Thanks very much for your fast reply. I feel kind of guilty because your basically writing this program for me with these tips. I really do appreicate your help. You've saved me so much time! Thanks again!
Mar 15 '11 #7
NeoPa
32,557 Recognized Expert Moderator MVP
Your boss clearly has experience with interfaces and how important that is when designing software.

Smiley's solution includes everything I brought up, except what you put on the form is down to you of course, including the slight change to the spec from the original question (Different events required for CommandButton than CheckBox controls). He's even warned you about the continuous forms issue. As they say "You're good to go!"
Mar 15 '11 #8
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Your welcome.

Don't spend time on being guilty, spend the time on understanding WHY/HOW the code works. Too many people just copy code from this site(or others), without spending a single minute on understanding WHY/HOW it works.
Mar 15 '11 #9

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

Similar topics

0
366
by: Alex | last post by:
I found some good information On "Including a Data Bound CheckBox in an Editable DataGrid... " at this site http://www.dedicatedsolutions.co.uk/DesktopDefault.aspx?tabid=62 It is worth the click
2
3264
by: Zvonko Bičkup | last post by:
Hi! I have 5 checkboxes with the same name: <input type="checkbox" name="check" value="XYZ" /> <input type="checkbox" name="check" value="ZXY" /> <input type="checkbox" name="check" value="MHG"...
3
3295
by: paoparaopao | last post by:
Hi, I am creating a new screen in a GUI. Can someone help me how can I make a checkbox look like it is enabled? For example, I use this code EUAMIndCheckBox.setEditable(false); and the checkbox...
4
13655
by: sara | last post by:
Hi - I've looked at many posts, and cannot find the answer on this specific problem. I have several fields on a table, which I've defined as "Text", 3 characters, Format Yes/No (I picked up the...
2
2764
by: JLC | last post by:
Hi, I am creating a page in asp.net that has a checkbox and a textbox. When the checkbox is checked I want the textbox to become active and show text. If the checkbox is unchecked, I would like...
2
5407
by: dkultasev | last post by:
Hello, I have small script which generates some listboxes. Their names are listXX (list01, list02, list03....). How to check if there are checked or not ? If I have 1 listbox and have it's name I...
5
1351
nev
by: nev | last post by:
i use mysql. i have a bound checkbox which returns 'checked' or 'unchecked' values into my database. what i want to achieve is for it to inject 1 or 0 into my database. how do?
3
12213
by: Jill1975 | last post by:
I work with a large group of people who enter tons of records each day. To seach for a specific record takes a long time. To help manage this, I have duplicated the form. One form will hold all...
3
3795
by: SoNew | last post by:
I am trying to add a checkbox to a form and am having a rather basic problem. As you will quickly tell I am not an access person, but my boss seems to think so :) Anyhow, I needed to add a field...
13
17248
wordbrew
by: wordbrew | last post by:
Hopefully this has a simple solution either by VBA or in the properties box. I have a report in Access called JeppList in which the field is pulling the data from my form entitled OrderForm from...
0
7224
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
7323
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
7379
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...
1
7038
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
7493
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...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.