Results 1 to 9 of 9
  1. #1
    RichardM is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2020
    Location
    richardmumma
    Posts
    6

    Using checkboxes in queries with parameters derived from forms.


    This should be a simple problem to resolve but so far it has stumped me.
    I have created a single table query.
    I am using a form so the user can select which data they wish to select, i.e., query by example.
    The input form includes one drop down box and 4 check boxes. The table columns included in the query are one short text data type, and 4 yes/no data types (I assume are binary).
    The fields in the input form match the data types of the columns in the query.
    Using the expression builder, I have inserted the fields from the form into the parameter row of the query. I have set the default value of the checkbox fields to "No"

    But, it doesn't work. All attempts to query returns no records. I have tried a number of variations with no success.

    So, what am I missing?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    If you need complex form filters THEN make a query from it, do this:
    NOTE: THE QUERY MUST ALREADY EXIST.
    Code:
    Public Sub btnReport_Click()
    Dim sSql As String, sWhere As String
    Dim qdf As querydef
    Const kQRY = "qsFormFilter"    'here is the query we use ...in the report too
    
    sWhere = "1=1"
        'the query is built depending on the various filters the user picks...
    If Not IsNull(cboState) Then sWhere = sWhere & " and [state]='" & cboState & "'"
    If (chkIsRegisterd) Then sWhere = sWhere & " and [Registered]=true "
    If (chkContact) Then sWhere = sWhere & " and [Contact]=" & chkContact.Value
    
    
    'IF you just want to filter records
    if sWhere = "1=1" then
      me.filterOn = false
    else
      me.filter = sWhere
      me.filterOn = true
    endif
    
    
    'or     'BUILD the query from the 'where'
    Set qdf = currentdb.querydefs(kQRY)
    qdf.Sql = "SELECT * FROM tblCompany WHERE " & sWhere
    qdf.Close
    
     'open the query or report here!
    DOCMD.openquery kQRY
    'or open the report based on the query
    'DOCMD.OPENREPORT "rMyReport"
    SET qdf = nothing
    End Sub

  3. #3
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    @RichardM,
    What you are asking is kinds like asking "I tried to get to Joe's house. I followed the instructions, but ended up at the Post Office". What did I do wrong?"

    It is helpful to provide the dB, a sample db, the SQl of the query, an image if the table/relationships, etc.
    So maybe you would post the SQL?
    You might/will get a more focused answer....

  4. #4
    RichardM is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2020
    Location
    richardmumma
    Posts
    6
    Quote Originally Posted by RichardM View Post
    This should be a simple problem to resolve but so far it has stumped me.
    I have created a single table query.
    I am using a form so the user can select which data they wish to select, i.e., query by example.
    The input form includes one drop down box and 4 check boxes. The table columns included in the query are one short text data type, and 4 yes/no data types (I assume are binary).
    The fields in the input form match the data types of the columns in the query.
    Using the expression builder, I have inserted the fields from the form into the parameter row of the query. I have set the default value of the checkbox fields to "No"

    But, it doesn't work. All attempts to query returns no records. I have tried a number of variations with no success.

    So, what am I missing?
    I am going to try to submit a reply:
    Database is too large to upload. I will have to make a sample.

  5. #5
    RichardM is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2020
    Location
    richardmumma
    Posts
    6
    I placed the code into an onClick event on a button of the form.
    It threw the following error, "You canceled the previous operation" at this point in the code "DoCmd.OpenQuery kQRY"

  6. #6
    RichardM is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2020
    Location
    richardmumma
    Posts
    6
    I placed the code into an onClick event on a button of the form.
    It threw the following error, "You canceled the previous operation" at this point in the code "DoCmd.OpenQuery kQRY"

  7. #7
    RichardM is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2020
    Location
    richardmumma
    Posts
    6
    Quote Originally Posted by ssanfu View Post
    @RichardM,
    What you are asking is kinds like asking "I tried to get to Joe's house. I followed the instructions, but ended up at the Post Office". What did I do wrong?"

    It is helpful to provide the dB, a sample db, the SQl of the query, an image if the table/relationships, etc.
    So maybe you would post the SQL?
    You might/will get a more focused answer....
    Here is a sample,
    PrepareSample.accdb

  8. #8
    RichardM is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2020
    Location
    richardmumma
    Posts
    6
    Not sure what the problem was but I rebuilt the search form and everything stated to work. So, for now, the problem is resolved.

  9. #9
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Great. But I have to tell you there are a number of other issues you should take care of.

    Good luck with your project and welcome to the forum....

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 09-12-2016, 06:52 AM
  2. Replies: 18
    Last Post: 09-10-2016, 05:22 PM
  3. Parameters in queries
    By BrendaP in forum Access
    Replies: 9
    Last Post: 08-20-2015, 10:33 AM
  4. Update more queries with the same parameters
    By Christian1977 in forum Programming
    Replies: 4
    Last Post: 06-28-2013, 02:57 AM
  5. Form queries. Multiple checkboxes.
    By radink in forum Queries
    Replies: 4
    Last Post: 04-27-2011, 07:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums