Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 19th, 2005, 12:29 PM
Registered User
 
Join Date: Feb 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Checkbox problem

I have a search form with 21 check boxes on, I have to perform a search depending on which check box has been checked. There can be any number of boxes checked.

My problem is, how do I work out which box or boxes have been checked and pass the results to the SearchResults form?
Regards
peter

 
Old February 19th, 2005, 09:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi peter,

Have a peak at:

http://p2p.wrox.com/topic.asp?TOPIC_ID=25668

You might find it useful. Its how I routinely do multiple-parameter searches. The search form builds the appropriate WhereCondition string in code, stores it in the variable strWhereCondition, then opens a search results form filtered by the WhereCondition.

DoCmd.OpenForm FormName:="frmSearchResults", WhereCondition:=strWhereCondition

To add checkbox criteria to the WhereCondition building code, add a parameter like:

  '-----------------------------------------------------------------
  ' 5. Build BatteriesIncluded parameter
  '-----------------------------------------------------------------

    If Me!chkBatteriesIncluded Then
        If IsNothing(strWhereCondition) Then
            strWhereCondition = "([BatteriesIncluded] Is Not Null)"
        Else
            strWhereCondition = strWhereCondition & " AND ([BatteriesIncluded] Is Not Null)"
        End If
    End If

HTH,

Bob

 
Old February 19th, 2005, 09:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Or you might need:

If Me!chkBatteriesIncluded Then
        If IsNothing(strWhereCondition) Then
            strWhereCondition = "(Not [BatteriesIncluded])"
        Else
            strWhereCondition = strWhereCondition & " AND (Not [BatteriesIncluded])"
        End If
End If

or

If Me!chkBatteriesIncluded Then
        If IsNothing(strWhereCondition) Then
            strWhereCondition = "[BatteriesIncluded]"
        Else
            strWhereCondition = strWhereCondition & " AND [BatteriesIncluded]"
        End If
End If

If BatteriesIncluded is a boolean (Yes/No) field, the first snippet above would fulfill a request for a checkbox labeled:

"Don't list products that include batteries"

In my previous post, BatteriesIncluded would be a text field in your data source that stores the type of batteries included. So:

 If Me!chkBatteriesIncluded Then
        If IsNothing(strWhereCondition) Then
            strWhereCondition = "([BatteriesIncluded] Is Not Null)"
        Else
            strWhereCondition = strWhereCondition & " AND ([BatteriesIncluded] Is Not Null)"
        End If
    End If

would fulfill a request for a checkbox labeled:

"List all products that include batteries" (i.e., the BatteriesIncluded field isn't null).

It all depends on what type of data your check boxes indicate should be included in the query.

HTH,

Bob









 
Old February 20th, 2005, 05:17 AM
Registered User
 
Join Date: Feb 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok Bob
thanks for the quick reply, I'll give it a try..






Similar Threads
Thread Thread Starter Forum Replies Last Post
multi checkbox problem deean Classic ASP XML 0 June 30th, 2008 12:43 AM
Checkbox indeterminate problem (I think) irishlad67 VB Databases Basics 2 March 30th, 2008 12:35 PM
checkbox problem sarvesh189 ADO.NET 1 March 21st, 2005 03:44 AM
CheckBox Insert Problem blink Classic ASP Databases 1 September 4th, 2003 12:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.