• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

VBA - Set checkbox value

See frmDatasheet

Note the big silver button in the yellow section of the form.

This button (in theory) toggles the value of the tick box.

However it toggles to a "ticked" but does not toggle back to "no tick".

QUESTION: Why won't the button toggle properly via my VBA?
WealthMan.accdb
0
Patrick O'Dea
Asked:
Patrick O'Dea
  • 2
2 Solutions
 
MacroShadowCommented:
You can use any of the following:
Me.OptOut = -1 = Me.OptOut.Value = 0

Open in new window

    If Me.OptOut = -1 Then
        Me.OptOut.Value = 0
    ElseIf Me.OptOut = 0 Then
        Me.OptOut.Value = -1
    End If

Open in new window

    If Me.OptOut = -1 Then
        Me.OptOut.Value = 0
    Else
        Me.OptOut.Value = -1
    End If

Open in new window

0
 
Dale FyeCommented:
Or

me.OptOut = NOT NZ(me.OptOut, 0)

Which will handle the situation where you inadvertently allow NULLs in a Yes/No field
0
 
Patrick O'DeaAuthor Commented:
Neat solution!
0
 
Dale FyeCommented:
glad to help.

I use this type of syntax a lot.  But the code that Macro posted is far more readable for either a new programmer or for someone tasked with taking over your code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now