Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    tarhim47 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    57
    Ok.



    Do you have any idea as to why I'm getting an error?

    Thanks!

  2. #17
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,526
    Not offhand, though you may be comparing a string wherecondition to a numeric client ID. Can you post the db with this code in it?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #18
    tarhim47 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    57
    Hey Paul,

    Actually I figured it out...I shouldve had County where I had Client ID.

    THANKS for all your help!!!!! Hope I wasnt too much trouble.

    Have a good one.


  4. #19
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,526
    That's what I said in post 15. Glad you got it sorted out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #20
    tarhim47 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    57
    Oh...sorry! I guess I was reading quickly.

  6. #21
    tarhim47 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    57
    Hi Paul,

    I was just wondering if I can ask you another question.

    I got the form working with the changes you suggested. However when I add another list box for the type of cow, the form isnt able to filter the query.

    Can you tell me what I'm missing here? I basically copied the code for the county and changed it to refer to the type of cow. Why doesnt this work?

    Thanks!

    My code is as follows:
    Option Compare Database
    Option Explicit

    Private Sub OK_Click()
    On Error GoTo Err_OK_Click

    Dim strWhere As String
    Dim ctl As Control
    Dim varItem As Variant
    'make sure a selection has been made
    If Me.Enter_county_of_farm_operations.ItemsSelected.C ount = 0 Then
    MsgBox "Must select at least 1 county"
    Exit Sub
    End If
    'add selected values to string
    Set ctl = Me.Enter_county_of_farm_operations
    For Each varItem In ctl.ItemsSelected
    'strWhere = strWhere & ctl.ItemData(varItem) & ","
    'Use this line if your value is text
    strWhere = strWhere & "'" & ctl.ItemData(varItem) & "',"
    Next varItem
    'trim trailing comma
    strWhere = Left(strWhere, Len(strWhere) - 1)
    'open the report, restricted to the selected items
    DoCmd.OpenReport "Report", acPreview, , "County IN(" & strWhere & ")"
    'make sure a selection has been made
    If Me.Enter_type_of_cows.ItemsSelected.Count = 0 Then
    MsgBox "Must select at least 1 type of cow"
    Exit Sub
    End If
    'add selected values to string
    Set ctl = Me.Enter_type_of_cows
    For Each varItem In ctl.ItemsSelected
    'strWhere = strWhere & ctl.ItemData(varItem) & ","
    'Use this line if your value is text
    strWhere = strWhere & "'" & ctl.ItemData(varItem) & "',"
    Next varItem
    'trim trailing comma
    strWhere = Left(strWhere, Len(strWhere) - 1)
    'open the report, restricted to the selected items
    DoCmd.OpenReport "Report", acPreview, , "Type_of_cows IN(" & strWhere & ")"

    Exit_OK_Click:
    Exit Sub
    Err_OK_Click:
    MsgBox Err.Description
    Resume Exit_OK_Click
    End Sub

  7. #22
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,526
    The report is static; it's already open with the first criteria, so it won't change with the second. You'd have to build a combined string with an end result like:

    "County In('abc', 'def') AND Type_of_cows IN('aaa', 'bbb')"

    So basically you build the first one and then add the second.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. 2 multi select list boxes on one search form
    By woodey2002 in forum Forms
    Replies: 2
    Last Post: 11-05-2010, 12:44 PM
  2. Multi-select List Boxes
    By Rawb in forum Programming
    Replies: 6
    Last Post: 09-21-2010, 09:02 AM
  3. Search form with list boxes
    By scottay in forum Programming
    Replies: 15
    Last Post: 07-27-2010, 09:28 AM
  4. List Boxes.
    By Willtc in forum Programming
    Replies: 2
    Last Post: 02-12-2010, 04:12 AM
  5. List box to populate other list boxes
    By Nathan in forum Forms
    Replies: 0
    Last Post: 03-03-2009, 07:22 PM

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