Results 1 to 4 of 4
  1. #1
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    101

    SELECT a combobox option using the selection of a listbox on another form

    Hello all,

    So I have two forms:


    1. The first one has three comboboxes and one listbox (Area, Subarea, station and operator correspondingly), all of them are filtered in cascade through different queries.
    2. The selection of the last listbox (operator) opens up a second form with a listbox in it, which shows the same options as the third (stations) combobox in the previous form but filtered differently (through operator instead of subarea).


    What I need this to do is that:
    • When I select a station in the listbox of the second form and click the button, it takes you back to the first form and auto select the corresponding area in combobox 1, subarea in combobox 2 and combobox 3 should have the same station as selected in the listbox of form 2.
    • I created a query that links area, subarea and station to ease a lookup...




    • I'm thinking about a code thaton click on button "ok" in form "frm2":
      1. Go to the first combobox "cboArea" in form "frm1"
        1. Select in combobox "cboArea" the corresponding value to the lookup in query "QryRelation" column "Area" related to the "Station" selected in listbox "lstStation" in form "frm2"

      2. Go to the second combobox "cboSub" in form "frm1"
        1. Select in combobox "cboSub" the corresponding value to the lookup in query "QryRelation" column "Subarea" related to the "Station" selected in listbox "lstStation" in form "frm2"

      3. Go to the third combobox "cboStation" in form "frm1"
        1. Select in combobox "cboStation" the "Station" selected in listbox "lstStation" in form "frm2"


    how could I have that sequence in code?

    thanks for your time!

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    use FULL paths of the object on the form. (use the Builder to get the pathnames correct)

    forms!form1!cboBox1 = forms!form2!lstBox2

  3. #3
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    101
    Quote Originally Posted by ranman256 View Post
    use FULL paths of the object on the form. (use the Builder to get the pathnames correct)

    forms!form1!cboBox1 = forms!form2!lstBox2
    I typed this in the On Click field without succes:

    =[Forms]![frm20MainStatus]![cmbSub]=DLookUp("[Subarea]","[Qry-xreference]","[Station Description]='" & [Forms]![frm30UserData]![lstStation] & "'")

    According to me, I'm saying that cmbSub in frm20... has to be equal to the value in column subarea in form Qry-xref... by finding in column station description the value selectec in lststation in frm30...

    but it is not working, what am I doing wrong?

  4. #4
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    101
    If anyone have a similar situation, the code to do it was the following:

    Code:
    Private Sub btnStation_Click()    Dim AreaLookUp As String
          AreaLookUp = DLookup("Area", "Qry-xreference", "StationDescription='" & Forms!frm30UserData!lstStation & "'")
        [Forms]![frm20MainStatus]![cmbArea] = AreaLookUp
        Dim SubLookUp As String
          SubLookUp = DLookup("[Subarea]", "[Qry-xreference]", "[StationDescription]='" & [Forms]![frm30UserData]![lstStation] & "'")
        [Forms]![frm20MainStatus]![cmbSub] = SubLookUp
    [Forms]![frm20MainStatus]![cmbStation] = [Forms]![frm30UserData]![lstStation] & ""
    [Forms]![frm20MainStatus].Refresh
    End Sub

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

Similar Threads

  1. Replies: 2
    Last Post: 01-20-2017, 10:26 AM
  2. Combobox selection populates Listbox
    By Thompyt in forum Programming
    Replies: 9
    Last Post: 09-24-2015, 01:55 PM
  3. Replies: 1
    Last Post: 09-10-2012, 11:21 PM
  4. Replies: 16
    Last Post: 11-01-2011, 01:35 PM
  5. Replies: 0
    Last Post: 08-24-2010, 06:38 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