If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Can't set Value of check box in VBA

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Apr 2005
Posts: 61
Can't set Value of check box in VBA

OK I'm having a problem setting the Value of a Checkbox in Vba.

I've tried: CheckBoxName.Value = True and this doesn't work. I receive the error You can't assign a vlue to this object.

How do you set the value of a check box to true or false?

Thanks for your help in advance.

Mythos
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Jan 2002
Location: Bay Area
Posts: 507
Try this: Me.chkBox.Value = 1
or Me.chkBox.Value = 0 (to remove the check).

Jerry
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Apr 2005
Posts: 61
Didn't work

I tried what you posted but I received the error you can't assign a value to this object.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Jan 2002
Location: Bay Area
Posts: 507
I'm sorry--I have an application with that logic to clear the check box: Me.chkBox.Value = 0. In debug, I see that the value is -1 when checked. See if assigning the value -1 works.
Jerry
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Apr 2005
Posts: 61
Still Nothing

I've tried -1 0 and 1 and it states that I can not assigne a vlue to this object.
Reply With Quote
  #6 (permalink)  
Old
Moderator
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 2,500
YourCheckBoxName.Value = 1 should "check" the box. I just did that very thing and itworked fine. Can you post your code exactly as it appears, i.e. the entire sub it resides in?
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2003/2007
Reply With Quote
  #7 (permalink)  
Old
Registered User
 
Join Date: Jan 2002
Location: Bay Area
Posts: 507
In form design mode, look at the properties for the checkbox, data tab. The Control Source should be blank. Enabled should be set to 'Yes'. Assign the default value -1, open your form and observe that the checkbox is checked (to show that the object can be assigned a value when the form loads).

After I have viewed object's values in debug mode and still can solve it, I delete the object and create a new one.

Good luck.
Jerry
Reply With Quote
  #8 (permalink)  
Old
Registered User
 
Join Date: Apr 2005
Posts: 61
It is now working

Ok I deleted the checkbox and recreated it. I also relised that I placed it in an option group. Not sure if that could cause the problem. So, I recreated it outside the option group and it's working now.

thanks for all the help.


Mythos.
Reply With Quote
  #9 (permalink)  
Old
Registered User
 
Join Date: Jan 2009
Posts: 5
Follow up question to the original poster

I have a similar issue, but I'm getting a different error message. I want to check a box if any field in the same record is modified. I was attempting to do this using an "AfterUpdate" code.

For instance, After my field AE is updated, I want my field New_Job (in the same record) to be checked.

Private Sub AE_AfterUpdate()
Me.New_Job.Value = -1
End Sub

I've tried this several different ways, but ultimately I get an error message stating "Module not found" and it takes me to my Debugger screen.

Is there a better way to write this code since I ultimately have ~8 fields that I want to check for updates? I want the check box marked if any of the fields are updated.

Thanks in advance from a fairly new programmer in Access!
Reply With Quote
  #10 (permalink)  
Old
Computer Monkey
 
Join Date: May 2005
Posts: 1,191
Quote:
Originally Posted by gindles
I've tried this several different ways, but ultimately I get an error message stating "Module not found" and it takes me to my Debugger screen.
My first hunch would be to check that your Form's Has Module property is set to True.
Otherwise, could you post a screenshot of the error message, or at least the full text?
Attached Images
File Type: bmp HasModule.bmp (11.7 KB, 315 views)
__________________
Me.Geek = True
Reply With Quote
  #11 (permalink)  
Old
L33t Helpa Munky
 
Join Date: Nov 2007
Location: Adelaide, South Australia
Posts: 4,049
Sounds like corruption to me. "Module not found" is NOT a normal thing.

If a form has no module and you put code in that form, Access will create a module for the form, and set Has Module to Yes.

If you set Has Module to No, then all the code from the form will be lost and the module removed. Access would then have no reason to look for it.

To have a form produce that message would make me want to take a redundant backup and look at things like compact / repair / decompile etc.
__________________
Owner and Manager of
CypherBYTE, Microsoft Access Development Specialists.
Microsoft Access MCP.
And all around nice guy!


"Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
"...teach a man to code and he'll be frustrated for life! " -- georgev
Reply With Quote
  #12 (permalink)  
Old
Registered User
 
Join Date: Jan 2009
Posts: 5
Thanks for the ideas

To answer the first question - yes. The Has Module property is set to yes in both the form and subform (the coding is for the subform actually).

As far as corruption, I tried that route but thus far have been unsuccessful. I have worked off of backup copies and even worked off of older backup copies where I remade the forms. The database always works fine until I put that specific line of code in, or any code looking for an update.

If I take that code out, the db works fine.

I also noticed that I keep getting an error message stating referencing "Form1", which I do not have anywhere in my database. I can't delete it from my VBA window either. I'm wondering if this has something to do with my problem.

Click to enlarge.
Can't set Value of check box in VBA-picture1.jpg

I think I'm going to attempt to copy and paste all my tables and files in to a new database and compile again. I'm curious to see if this Form1 shows up in the new database. Perhaps that will solve the problem.
Reply With Quote
  #13 (permalink)  
Old
Registered User
 
Join Date: Jan 2009
Posts: 5
Latest update...problem solved

Well I solved the problem and it appears to be working now. I copied all my tables, macros, forms etc to a new database. I verified that the mysterious "Form1" was not in my VBA, and it was not. After verifying that all links worked, I dropped in my code and voila...it works.

Thanks for the help.
Reply With Quote
  #14 (permalink)  
Old
L33t Helpa Munky
 
Join Date: Nov 2007
Location: Adelaide, South Australia
Posts: 4,049
In other words, you fixed the corruption

Congrats
__________________
Owner and Manager of
CypherBYTE, Microsoft Access Development Specialists.
Microsoft Access MCP.
And all around nice guy!


"Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
"...teach a man to code and he'll be frustrated for life! " -- georgev
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On