Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

how to check if a checkbox is checked or not

nethervoidnethervoid Posts: 4Member
I'm trying to add in a "save username and password" checkbox on my excel sheet, but can't seem to call it from the code. I can't find how to reference it from the code, so I can see if it's checked or not.

I tried:

chbxSaveUNPW.checked = false
chbxSaveUNPW.value = 0
sheet2.chbxSaveUNPW.value = 0

The code doesn't recognize my checkbox. =( How do I reference an object on a sheet? I don't want to run a macro when it's clicked, just want to see if it's checked or not.

Comments

  • PavlinIIPavlinII Posts: 404Member
    : I'm trying to add in a "save username and password" checkbox on my excel sheet, but can't seem to call it from the code. I can't find how to reference it from the code, so I can see if it's checked or not.
    :
    : I tried:
    :
    : chbxSaveUNPW.checked = false
    : chbxSaveUNPW.value = 0
    : sheet2.chbxSaveUNPW.value = 0
    :
    : The code doesn't recognize my checkbox. =( How do I reference an object on a sheet? I don't want to run a macro when it's clicked, just want to see if it's checked or not.
    :
    Hi,
    if you've place checkbox on your sheet, excel creates the instance of it. I suppose you've rename it to cbxSaveUNPW..
    When you're accessing the checkbox from outside codebehind of your sheet (let's say sheet2), you have to use whole name like sheet2.chbxSaveUNPW..
    so your code looks all right..
    Try to take a look at the name of the check box (I would use cbxSaveUNPW instead of chbxSaveUNPW...). And when you're starting to write the name, VBA intellisence will offer you your check box, so if it does not, there's mistake in the name of it..

    When you're checking if checkbox is checked in VBA, use .Value (boolen).
    Try
    MsgBox Sheet2.chbxSaveUNPW.Value
    for debug..

    Hope this helps.

    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


  • nethervoidnethervoid Posts: 4Member
    That didn't work.

    When I type 'sheet2', I don't find my checkbox in the list. I tried to locate it in the object browser, but I can't even find it there.
  • PavlinIIPavlinII Posts: 404Member
    : That didn't work.
    :
    : When I type 'sheet2', I don't find my checkbox in the list. I tried to locate it in the object browser, but I can't even find it there.
    :
    Hmmm..
    it looks like some deeper excel problem.. What version of it are you using? (Check, if macros are enabled in your app but I suppose they are..)



    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


Sign In or Register to comment.