Results 1 to 4 of 4
  1. #1
    jgelpi is offline Novice
    Windows XP Access 2003
    Join Date
    May 2009
    Posts
    19

    Question Combo Box Filter

    I have a combo box with a couple different report options. However, not all of the reports correspond with another value on the form. I need a way to filter out one of the form options if the form value in the other text box is a certain value(s).
    i.e.


    Code:
     
    if text1 = 1 or text1 = 2 or text1 = 3 then
    combo1 list = a, b, c, d
    else
    combo1 list = a, b, c
    I am using an SQL statement to choose which report options are visible in the "combo1" as I have a table that defines the reports, and which is viewable by specific users (Managers and Employees).

  2. #2
    tlittell is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2009
    Location
    Pittsburgh, PA
    Posts
    8
    Tests for textbox value; assigns the combo box rowsource based on the query you assign. Let me know if this helps.

    Code:
     
    Private Sub Combo1_GotFocus()
    Combo1.RowSourceType = "Table/Query"
        If Text1.Value = 4 Or Text1.Value = 3 Then
            Combo1.RowSource = "select test1.total from test1 where test1.count = 4"
            Else
            If Text1.Value = 5 Then
            Combo1.RowSource = "select test1.total from test1 where test1.count = 5"
            Else
            Combo1.RowSource = "select test1.total from test1"
            End If
        End If
    End Sub

  3. #3
    jgelpi is offline Novice
    Windows XP Access 2003
    Join Date
    May 2009
    Posts
    19
    I'm not sure if I'm understanding how that code works. I am actually using an SQL statement in the combo box to filter out the options I want. Here is the statement that I have set up, but something in the "IIF" statement keeps triggering the error "This expression was typed incorrectly, or it is too complex to be evaluated."

    Code:
    SELECT TblReports.LetterName, TblReports.ScreenName, TblReports.RptNo, TblReports.EmpType FROM TblReports WHERE (((TblReports.RptNo)=IIf([Forms]![frmNonITAS_RO]![txtAcctType]=1 Or [Forms]![frmNonITAS_RO]![txtAcctType]=2,[RptNo],[RptNo]<>144)) AND ((TblReports.EmpType)="RO")) ORDER BY TblReports.ScreenName;

  4. #4
    tlittell is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2009
    Location
    Pittsburgh, PA
    Posts
    8
    I'm assuming you are referencing your query in the Rowsource property of the combobox. If that is true, a simple query wont look at your form to determine the value of your txtAcctType textbox. When you click the combobox does it give you a pop up asking for the value of txtAcctType?

    You need to use some code. Add this code to you form. Replace Combo1 with the name of your combo box. Add line breaks in queries as needed.

    Code:
    Private Sub Combo1_GotFocus()
    Combo1.RowSourceType = "Table/Query"
        If txtAcctType.Value = 1 Or txtAcctType.Value = 2 Then
            Combo1.RowSource = "SELECT TblReports.LetterName, TblReports.ScreenName,TblReports.RptNo, TblReports.EmpType
     FROM TblReports
     WHERE TblReports.EmpType="RO" ORDER BY TblReports.ScreenName"
            Else 
     Combo1.RowSource = "SELECT TblReports.LetterName, TblReports.ScreenName,TblReports.RptNo, TblReports.EmpType
     FROM TblReports
     WHERE tblReport.RptNo<>144 and TblReports.EmpType="RO" ORDER BY TblReports.ScreenName"
        End If
    End Sub
    Hope this helps.

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

Similar Threads

  1. Filter Form records with Combo Box????
    By jgelpi in forum Forms
    Replies: 0
    Last Post: 05-19-2009, 07:05 AM
  2. Continuous Subforms Filter Dependant Combo
    By BigBear in forum Forms
    Replies: 0
    Last Post: 04-19-2009, 08:13 AM
  3. Replies: 3
    Last Post: 02-26-2009, 10:17 AM
  4. Applying a filter to a combo box
    By bugchaser in forum Programming
    Replies: 1
    Last Post: 02-20-2009, 02:37 PM
  5. Replies: 0
    Last Post: 08-17-2008, 12:19 PM

Tags for this Thread

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