Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox Won't Work 3

Status
Not open for further replies.

Quintios

Technical User
Mar 7, 2002
482
US
I put a checkbox on a form and it won't work.

The form that the checkbox is on is not based on any data; it's just a menu with buttons for navigation. I want to use the checkbox on the form to modify what form is brought up when a user has the checkbox selected and then clicks a navigation button. The checkbox is to be used for a "short view", where a form comes up with minimal fields as opposed to the standard "long view" version of the form which takes up more of the screen. Anyway, that might be too much information there...

I tried connecting the checkbox to a table field that is set to 'yes/no' and it doesn't work. It doesn't work when it's NOT connected to a table. It just won't let me change it's value.

Help! This seems simple and it's driving me nuts...

Thanks in advance,
Onwards,

Q-
 
Hi Q!

If you can't change the value of the check box then you will want to look at the properties of the check box to make sure it isn't disabled or locked. Then check the poperties of the form to make sure that allow edits isn't turned off.

hth


Jeff Bridgham
bridgham@purdue.edu
 
Enabled: Yes
Locked: No
TripleState: No
Tab Stop: Yes


I compared the properties to another working Checkbox. They are the same. I did change the name of the checkbox. Could that have something to do with it? There's no code behind it, just a checkbox. At the moment it doesn't have a control source, but it wouldn't work with or without so I've just left it alone.

ANY OTHER SUGGESTIONS?

Onwards,

Q-
 
Sub Command_Button_Click()

if Me!YourCheckbox = -1 then
DoCmd.OpenForm "Long Form"
else
DoCmd.OpenForm "Short Form"
End if
End Sub

OR:

dim StrCriteria as string
StrCriteria = IIF(Me!CheckBox, "Long Form", "Short Form")

DoCmd.OpenForm strCriteria


Unless you changed it and didn't tell anyone, your checkbox should return a -1 (negative one) if it's checked, and a 0 (zero) if it's not.

Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
 
Now here's the trick, how can I get the checkbox setting to stay? If the user wants the short form they're probably going to be using it as a default.

How can I give the 'ol checkbox some memory? I fixed the problem with it not operating ('Allow Edits' was set to 'No') so it works now. I can't seem to attach it to a field in a separate table. I have a separate table called 'tblBasicInfo' and the syntax for control sources is:

=[tblBasicInfo]![ShortListView]

I also tried

=[tblBasicInfo]![ShortListView].[Value]

but neither would allow me to change the setting, nor did the setting reflect the value held in the table.

Does the table have to be open?
Onwards,

Q-
 
If you want an option like that to "stick", you'll probably want to store the value for it in a table somewhere so you can retrieve it when necessary.

Or look at the way they handle the "show me this form next time" checkbox on the opening splash of Northwind... Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
 
It won't work. See my post above. I can't get the value to attach to a table field.

I get this message:

"Control can't be edited; it's bound to the expression '[tblBasicInfo]![ShortListView]'."

What is that?
Onwards,

Q-
 
Hi Q!

The syntax for pulling the information from a table is:

=DLookUp("ShortListView", "tblBasicInfo")

I'm glad the allow edits worked, having given three possibilities I was hoping at least one would work! :)

hth

P.S. Will you need to store a default setting based on the user who has the Db open? If you will, we can share some possibilities.
Jeff Bridgham
bridgham@purdue.edu
 
Hey, thanks for the code! I was wondering when I'd have to use the DLookUp command.

OK, now it *takes* the value from the tblBasicInfo, but now I can't *change* it from the form. It's stuck with the value in the table.

With each post I'm getting closer! Keep 'em coming!!

(I won't be using this setting as per a user, this database will have only one "type" of user, and they'll want the setting.)

Onwards,

Q-
 
OK, the checkbox will now work and take the value of the field "ShortListView" in the table "tblBasicInfo", and I can change it when I open the form. However, I cannot save the value now.

How do I set the value of a field in a table using VBA? What I plan on doing is in the OnClose event, I'll change the value in the table to whatever the current checkbox indicates.

I understand there's a Forms collection and a Reports and Queries collections, but how do I change a value in a non-source table?

Onwards,

Q-
 
why not just Recordsource the form to the table. If this checkbox is the only thing there, who cares about any other junk on the form? That way, when you open the form, since the c/box is bound to the table, no code needed to 'save' the checkbox value.
Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
 
Because, (insert big huge whine here) I don't know how...

I'm not really sure how to apply it here.

Can you give me some generic code or point me to a help file or something?

Onwards,

Q-
 
Open the form in design view.
Open the Property sheet for the form.
Click "Data" tab.
Click in RECORDSOURCE property cell.
Type TBLBASICINFO
Make sure checkbox control source is same as your field in the table. - "shortListView"

Save Changes.


Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
 
Oh yeah. I thought you were refering to DAO or something. I tried setting the recordsource property, but doing that locks the checkbox and I can't change it. See my posts above as I described that particular situation.

I believe that I need to, in the OnClose event, take the value of the checkbox and stuff it into the table. I just don't know how. I can get the checkbox to take the value in the table as its default value, but if I set the recordsource property it locks it (it's grey, neither true nor false.)

I can't believe getting a checkbox to work is so much trouble!! :)

Thanks for all your help! Keep it coming!
Onwards,

Q-
 
It's still not working. Can someone help me?
Onwards,

Q-
 
Quintios, this IS a Yes/No field in your table, is it not? What else is in the table (record) structure? Do you have multiple records there, or just one? Are you sure you're positioning there? Are you sure the form isn't marked Allow Edits = NO or something that would prevent you from changing a record value?

This should be a snap to do, we're missing some important step here.

Ex-JimAtTheFAA
78.5% of all statistics are made up on the spot.
Another free Access forum:
 
I agree... This is a yes/no field. Edits are allowed. There's only one record in the table.

Just to make sure, I created a new blank database, created one table, created one form with one checkbox on it. Changed absolutely none of the default settings. The checkbox was set to:

control source =[tblBasicInfo]![CheckBox]
Default Value =DLookUp("CheckBox","tblBasicInfo")

In this database, not only does it NOT reflect the value in the table, but I can't change the value.

I gave up and went ahead and gave the form a recordsource. I didn't understand what you were saying before, WildHare, but now I do.

I went back and gave the form a Record Source and deleted the stuff in 'control source' and 'default value'. Since the form is just used for navigation it won't hurt anything for it to have a record source. I just figured this could be done, i.e. create a form without a RecordSource but have a Control Source point to a value in a table.

Thank you for your help!
Onwards,

Q-
 
Hi!

Setting the recordsource of the form is certainly the easiest way to handle this, but it can be done without that. If you set the control source to the DLookup as above, you can use the following code in the after update event procedure of the check box:

Dim rst As DAO.Recordset

Set rst = CurrentDB.OpenRecordset("YourTable", dbOpenDynaset)

rst.Edit
rst!YourField = Me!YourCheckBox.Value
rst.Update

Set rst = Nothing

Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top