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.
8 4073
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: - Private Sub chkBox_Click()
-
Me.chkBox.DefaultValue = Me.chkBox
-
End Sub
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.
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).
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!
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. - Private Sub Form_Current()
-
If Me.NewRecord And Me.chBox.DefaultValue Then
-
Me.Detail.BackColor = vbRed
-
Else
-
Me.Detail.BackColor = vbCyan
-
End If
-
End Sub
-
-
Private Sub togBtn_Click()
-
'Change default value
-
Me.chBox.DefaultValue = Not Me.chBox.DefaultValue
-
-
'Change caption on toggle button
-
If Me.chBox.DefaultValue Then
-
Me.togBtn.Caption = "Consignment Mode"
-
Else
-
Me.togBtn.Caption = "Other Mode"
-
End If
-
-
'If this is a newrecord and default is true, color it
-
If Me.NewRecord And Me.chBox.DefaultValue Then
-
Me.Detail.BackColor = vbRed
-
Else
-
Me.Detail.BackColor = vbCyan
-
End If
-
End Sub
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!
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!"
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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"...
|
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...
|
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...
|
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...
| |
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...
|
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?
|
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...
|
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...
|
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...
|
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,...
| |
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,...
|
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...
|
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...
|
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: 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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |