0

i'm trying to access the value of a checkbox I have in a separate form. I have no problem accessing the checkbox information from within it's own form using code...

If Not IsNull(Check43) Then
    If Check43 Then
        DoCmd.OpenQuery "Insert_Query"
    End If
End If

But I can't figure out how to access the value of "Check43" in another form. I thought something like below would work...

Dim frm As Form, ctl As Control
Set frm = Forms!Relevant_Application
Set ctl = frm!Check43

If Not IsNull(ctl) Then
    If ctl Then
        DoCmd.OpenQuery "Insert_Query"
    End If
End If

but even when the checkbox is checked, it doesn't work. It doesn't throw an error, it just skips over the function.

Bob
  • 1,344
  • 3
  • 29
  • 63
  • Looks ok. Are there subforms involved? [Refer to Form and Subform properties and controls](http://access.mvps.org/access/forms/frm0031.htm) -- Try stepping through the code and inspecting variables. [How to debug VBA code](http://www.cpearson.com/excel/DebuggingVBA.aspx) – Andre Apr 29 '19 at 14:46
  • Not necessary to use form and control object variables. If Check43 is in a subform, the path reference will be more complicated. The IsNull is also unnecessary. Is Check43 UNBOUND? Where are you calling this code? – June7 Apr 29 '19 at 15:18
  • Try `If (ctl) Then` or `If ctl = True Then` – BankBuilder Apr 29 '19 at 22:28

1 Answers1

0

Checkboxes do not store a null value, they store a boolean (-1 and 0). So if you change the logic from If Not IsNull(ctl) Then To If ctl = True Then it should work.

This was also addressed here.

To give credit where credit is due @BankBuilder did mention this before me.

Hope that helps. Best Regards.

EliSauder
  • 138
  • 1
  • 10