Share via

Checkbox Value to SQL String - Newbie VBA Q

Anonymous
2015-02-28T19:48:55+00:00

Hi all

I am trying to complete a query by form exercise.

So far I have unbound controls relating to both number and text fields and also a number of checkboxes.

The intention is to use vba code triggered by a command button to generate a concatenated string query.

The number field syntax works OK

If Not IsNull(txtItemNo) Then

If whereclause <> "" Then whereclause = whereclause & " AND "

whereclause = whereclause & "[ItemNo] = " & txtItemNo

End If

The text field syntax works OK

If Not IsNull(CmbDesign) Then

If whereclause <> "" Then whereclause = whereclause & " AND "

whereclause = whereclause & "[Design] = '" & CmbDesign & "'"

End If

If I have a yes/no field in my queried table called RVStatus and a check box named cbRVStatus on the query form, does anyone know the syntax for the corresponding clause which will test for yes (or true) and enter this value in a similar clause for the above query search string?

Many thanks

Phil

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2015-02-28T20:58:54+00:00

You'll find an extensive series of tutorials at http://www.functionx.com/vbaccess/

Was this answer helpful?

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2015-02-28T20:05:56+00:00

If you only want to add a condition if the check box is ticked:

    If Me.cbRVStatus = True Then

        If whereclause <> "" Then whereclause = whereclause & " AND "

        whereclause = whereclause & "[RVStatus] = True"

    End If

If you always want to add a condition corresponding to the value of the check box:

    If whereclause <> "" Then whereclause = whereclause & " AND "

    whereclause = whereclause & "[RVStatus] = " & Me.cbRVStatus

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2015-02-28T20:33:06+00:00

    Many thanks Hans

    The first clause is just the job.

    Are there any go to web sites that cover this "just above basic" level access and vba type content?

    I seem to be asking numerous questions which are sort of covered on forums but not quite.  I don't have the understanding yet to be able to transpose what I find into working code.  If there was a source of more examples spelled out for a dummy that would be a good start.

    Phil

    Was this answer helpful?

    0 comments No comments