Lucas Cunha
Lucas Cunha

Reputation: 37

Obtain Value from MS Access Checkbox

I have an Access database in which I store some data, and that database has 13 tables plus a reference one.

I want to make a form where there are several checkboxes and a button. Each chekbox represents a table, and every table selected will be joined inside a query writen in VBA, associated with the button click.

I've already made the same thing in Excel, and it works perfectly, so the only problem here is that I don't know how to access the checkbox value and use an IF condition to get the correct SQL string.

To make it clear, here I have a IF statement for one of the checkboxes in Excel:

If Range("B8").Value = True Then

    CTODStrc = ", CTODTYPE, CTOD.TEMPERATURE, VALIDITY,  DELTAR, DELTAL"
    CTODStr = " JOIN CTOD ON REF.ID = CTOD.REF_ID"
    JoinStr = JoinStr & CTODStr
    Columns = Columns & CTODStrc

End If

SQLStr = RefStr & JoinStr 'Query sentence

The SQLStr is the query text, and it has a prior "select" string which is added.

In Excel, the cell B8 was associated with the checkbox, but in Access I have to make this condition using a checkbox thats in the form - how can I do it?

I've tried Me.CbName.Value, but it says the command is not supported.

Thank you.

Upvotes: 0

Views: 2391

Answers (1)

Lee Mac
Lee Mac

Reputation: 16015

The checked state of a checkbox is given by the Value property of the checkbox control. This property may be 0 (unchecked), -1 (checked), or Null for a block-filled triple state checkbox.

Since the Value property is the default property for a checkbox, and assuming you are not using a triple state checkbox, you should be able to use simply:

If CBName Then
    ' Do stuff
End If

Upvotes: 1

Related Questions