Results 1 to 14 of 14
  1. #1
    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

  2. #2
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511
    Try this: Me.chkBox.Value = 1
    or Me.chkBox.Value = 0 (to remove the check).

    Jerry

  3. #3
    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.

  4. #4
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511
    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

  5. #5
    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.

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,571
    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

  7. #7
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511
    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

  8. #8
    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.

  9. #9
    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!

  10. #10
    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 Thumbnails Attached Thumbnails HasModule.bmp  
    Me.Geek = True

  11. #11
    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

  12. #12
    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.
    Click image for larger version. 

Name:	Picture1.jpg 
Views:	711 
Size:	60.9 KB 
ID:	9128

    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.

  13. #13
    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.

  14. #14
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •