Results 1 to 14 of 14
  1. #1
    FmrVBAJunkie is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    17

    Checkbox Question, and yes I've looked...

    Hi All,

    Err, kinda of embarrassed about this issue. I can't seem to set the value of my checkbox through VBA, and there is also some other weird stuff happening.

    The code and all of the possible numerations I tried, but to no avail they do not work...

    Code:
    Me.Checkbox1.Value = True
    Me.Checkbox1.Value = 0
    Me.Controls("checkbox1").Value = True
    Me.Controls("checkbox1").Value = 0
    The Properties:
    Control Source: <Blank>
    Triple State: No
    Default Value: No


    Validation Rule: <Blank>
    Validation Text: <Blank>
    Enabled: Yes
    Locked: No

    The weird stuff:
    I have two basic conditions that determine what state the checkbox will be in when the form opens.

    Condition 1:
    checkbox.Enabled = True
    *The checkbox's state is FALSE when the form opens. This works.

    Condition 2: c
    heckbox.Enabled = True
    checkbox.Value = DLookup()
    *But, no matter what I do, I can't set the value of the checkbox. The Dlookup returns a TRUE, and I pass it through a global variable before assigning it to the checkbox. The global variable is declared within the same module. Also under Condition 2, when the form opens, the value of the checkbox is "?", and the little grey box is inside. But, this confuses me because of the default value and the triple state property settings.

    I really don't know what to do. Can someone help me out?

    Thanks in Advance,
    FmrVBAJunkie

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    1. .value is not required - it is the default property of the control
    2. what is your full code for determining conditions 1 and 2 - and what event is it in?
    3. what is the code for your dlookup? - see this link

    https://support.office.com/en-us/art...ad=US&fromAR=1

    4. have you tried stepping through the code?

  3. #3
    FmrVBAJunkie is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    17
    Thanks for looking into this Ajax.

    1. .value is not required - it is the default property of the control
    I removed the .value, and re-ran the code. They still didn't change.

    2. what is your full code for determining conditions 1 and 2 - and what event is it in?
    There's only one place in the event that the checkbox value is being set. but the overall structure of the code is:

    Code:
    Button1_Click()
    BooleanVal = True
    Open Form1
    
    Button2_Click()
    BooleanVal = False
    Open Form1
    
    Private Sub Form1_Load_Form()
    Dim BooleanVal as Boolean
    Dim temPval as Boolean
    Dim RecordNumber as Integer
    
    If Boolean = True then
         checkbox.Enabled
    Else
         temPval = Dlookup("[Field Name]", "Table", "[Primary Key] = " & RecordNumber)
         checkbox.Enabled = True
         checkbox = temPval
    End if

    3. what is the code for your dlookup? - see this link

    Code:
    Dlookup("[Field Name]", "Table", "[Primary Key] = " & RecordNumber)
    https://support.office.com/en-us/art...ad=US&fromAR=1
    ~Thanks for the article.

    4. have you tried stepping through the code?
    Yes, and all of the parameter values pass as required, except to the checkbox. So, I'm sure that the syntax of the DLookUp function is okay.

    I hope this helps. I really don't know what's going on. Could there be a tools/reference issue?


    Thanks,
    FmrVBAJunkie

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    I think you can set its initial value using
    Me!CheckBox.DefaultValue = True in the Form_Load event of your form

    I created a sample unbound form with a checkbox and a button.

    Clicking the button reverses the value of the checkbox.

    Code:
    Private Sub Command2_Click()
    On Error GoTo Err_Command2_Click
    
    
       Me.Check0 = Not Me.Check0 
    
    Exit_Command2_Click:
        Exit Sub
    
    Err_Command2_Click:
        MsgBox Err.Description
        Resume Exit_Command2_Click
        
    End Sub
    And it works fine.
    Not sure what to advise?????


    I see there have been responses since I read your post.

    On reviewing, you may need to include the Me.checkbox but you aren't getting any errors re unknown control etc????

  5. #5
    FmrVBAJunkie is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    17
    Hi Orange,

    Yes, Me. is included. I left it out for the sake of brevity.

    Thanks for the code snippet, I put that one in my tool box. hehehe Also, the checkbox on condition2 is reflecting a field within a record. So, I pulled that value using the dlookup.

    Thanks for your response, atleast I know the hair that I lost over this wasn't due to failure.

    FmrVBAJunkie

    ~Leaving this open for now, just in case Ajax or someone else wants to take a swing at it.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    your code does not make sense to me - you set booleanVal to true, then false and I no idea what the open code does or what event is running it
    Code:
    Button1_Click()
    BooleanVal = True
    Open Form1
    
    Button2_Click()
    BooleanVal = False
    Open Form1
    and

    Dlookup("[Field Name]", "Table", "[Primary Key] = " & RecordNumber)
    do you really have a table called table and a field called field name.

    Table is a reserved word so would not be surprised if it doesn't work

    ditto for Boolean

    If Boolean = True then
    and what is this function?

    Private Sub Form1_Load_Form()

    If you are trying to get your code resolved and 'for the sake of brevity' missing bits out when all it takes is a copy and paste, then I can see I'm wasting my time trying to resolve non issues. So good luck with your project, but regret I am not willing to take a swing at it

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

    Frustrated because too much was cut out of your code.

    Code:
    Button1_Click()
    BooleanVal = True   '<<-- is "BooleanVal" a global variable or a control on the form??
    Open Form1
    
    
    
    Button2_Click()
    BooleanVal = False   '<<-- is "BooleanVal" a global variable or a control on the form??
    Open Form1
    This is the full code?

    Do you have
    Code:
    Option Compare Database
    Option Explicit
    at the top of EVERY code module? You should....


    Code:
    Private Sub Form1_Load_Form()
    Dim BooleanVal as Boolean      '<<-- not used
    Dim temPval as Boolean
    Dim RecordNumber as Integer      '<<-- not used
    
    If Boolean = True then      '<<-- is "Boolean" a global variable or a control on the form??
         checkbox.Enabled
    Else
         temPval = Dlookup("[Field Name]", "Table", "[Primary Key] = " & RecordNumber) ' <<-- where is the value for RecordNumber set????
         checkbox.Enabled = True
         checkbox = temPval
    End if

  8. #8
    FmrVBAJunkie is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    17
    I understand your frustration. Yes, yes the two options are at the top.

    The two buttons go to the same form, and depending on the Boolean value certain fields are locked. Condition2 displays record values. This is tripping me up to, because it should work.

    Is there a way to use hidden functions or procedures? Because, there are some checks being performed on a few fields but I can't find those checks. I know that they are there, because they are effectuated on the "Save" Button action. I looked at the modules and the fields on the forms. I can't find anything there. Also, the "view" tab from Tools/Option is not there. So, I can't "unhide" any modules/procedures/functions.

    Something might be interfering with my code from there.

  9. #9
    FmrVBAJunkie is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    17
    myself and another developer work on this db...

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also, the "view" tab from Tools/Option is not there. So, I can't "unhide" any modules/procedures/functions.
    To unhide tables, queries, forms, reports or modules, right click in a blank area of the database window and select "Navigation Options".
    In Display Options (bottom left), check "Show Hidden Objects". Click OK.
    In the database window, right click on the dimmed object (for instance a form) and click on "Unhide in this group".



    Case to post your dB for analysis?

  11. #11
    FmrVBAJunkie is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    17
    Hi Steve,

    Wish I could, but it's not mine to post. I'm smelling shenanigans :T with this DB. Is there any other place fields can be checked on the save action, other then a module or the controls' event handler?

    :T

  12. #12
    FmrVBAJunkie is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    17
    Hi All,

    Err...If anyone is still looking at this one. My DB is finally raising an error. '2448'. I read in another forum that I can't have the checkbox update from a query. Is this the case?

  13. #13
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    I read in another forum that I can't have the checkbox update from a query. Is this the case?
    What query? This is the first mention of an update query. And yes, it is true that a query cannot update a checkbox. However, I think it can update a boolean field in a table that the checkbox is bound to.

  14. #14
    FmrVBAJunkie is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2016
    Posts
    17
    Hi Davegri,

    Thanks a bunch. That helped out a lot. My first post showed a DLookUp function being used. I'm going to mark this thread as solved.

    Thank you everyone for looking into this.

    Tank!
    FmrVBAJunkie

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 10-16-2015, 04:42 PM
  2. Checkbox question
    By Blue in forum Forms
    Replies: 1
    Last Post: 01-07-2013, 06:59 PM
  3. Checkbox question
    By Medicmike in forum Access
    Replies: 4
    Last Post: 11-28-2011, 05:59 PM
  4. Checkbox Question
    By markod in forum Forms
    Replies: 4
    Last Post: 11-09-2010, 05:43 PM
  5. Yes/No Checkbox Question
    By Richard in forum Access
    Replies: 3
    Last Post: 10-07-2009, 03:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums