Results 1 to 5 of 5
  1. #1
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409

    Set rowsource of combobox

    Hi


    i have a form that i use to filter other forms (actually i'm building it)

    when i open this for it gets the recordsource of the form i want to filter (generally based on a query like "SELECT field1,field2 FROM something ORDER by somelse)

    i have a combobox that gets the fields of this recordsource, i select a field and then i want to set the rowsource of another combobox to all values in this field

    do you suggest something?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Sounds like cascading combobox (aka dependent combobox) - a very common topic. Yours has twists in that the table source and fields of primary combobox change. This does get complicated. Need some way to identify table. One way is to set form Tag property with name of table then reference that property in code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    thanks
    the problem is that some forms recordsource's is a table, other are based on queries.
    Some times i have calculated fields, so i'm building a complex structure

    Code:
    Private Sub Form_Open(Cancel As Integer)   
          If Me.OpenArgs <> "" Then
          Me.Caption = Mid(Me.OpenArgs, InStr(Me.OpenArgs, "\") + 1)
          Origin = Left(Me.OpenArgs, InStr(Me.OpenArgs, "\") - 1)
          MsgBox (Origin)
          Me.FldFilt.RowSource = Origin
          If Origin Like "SELECT*" Then
             If Origin Like "*order by*" Then
                FldOrigin = Mid(Origin, InStr(Origin, "From"), (Len(Origin) - InStr(Origin, "FROM") - 1) - (Len(Origin) - InStr(Origin, "Order by"))) ' estraggo la stringa sql fino all'eventuale "order by"
                MsgBox (FldOrigin)
             Else
                FldOrigin = Mid(Origin, InStr(Origin, "From"))
             End If
          Else
             FldOrigin = Origin
          End If
       End If
    End Sub
    openargs is the concatenation of the name of the form i want to filter and its recordsource

    Code:
    Private Sub Value1CB_GotFocus()   If FldOrigin = Origin Then
          Me.Value1CB.RowSource = "SELECT " & "[" & Me.FldFilt & "]" & " FROM " & "[" & FldOrigin & "]"
       Else
          Me.Value1CB.RowSource = "SELECT " & "[" & Me.FldFilt & "]" & " " & FldOrigin
       End If
    End Sub

    actually is working pretty good right now

  4. #4
    Join Date
    Apr 2017
    Posts
    1,679
    You can have an unbound combo to set filter for form. User can select from list of different filters, and combo's AfterUpdate event set's according filter for form, like:
    Code:
    The combo has RowSource like "1, 'FilterComment1', 2, 'FilterComment2, ..."
    
    YourUnboundCombo_AfterUpdate()
    
    Select Case Me.YourUnboundCombo
    Case 1
    Me.Filter = "SomeField1 = SomeValue1"
    Case 2
    Me.Filter = "SomeField2 = SomeValue2"        
    ...             
    End Select
    Me.FilterOn = True
    End Sub
    

  5. #5
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    thanks
    actually i upload criteria in a "filter" table that i see as subform. My filters are very complex, so i have many criteria for every field

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

Similar Threads

  1. Assign constants to combobox rowsource
    By klnlsu in forum Forms
    Replies: 4
    Last Post: 09-19-2018, 12:09 PM
  2. Combobox filtered rowsource?
    By TerraEarth in forum Access
    Replies: 4
    Last Post: 04-03-2018, 02:28 PM
  3. Replies: 13
    Last Post: 09-07-2017, 04:11 AM
  4. combobox rowsource per row on a subform
    By kowalski in forum Access
    Replies: 2
    Last Post: 12-05-2012, 01:49 AM
  5. combobox rowsource
    By dirkvw in forum Forms
    Replies: 3
    Last Post: 06-20-2011, 05:12 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