Making Railway Time table in excel using combo boxes & Text Boxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bhawesh9975
    New Member
    • Dec 2014
    • 1

    Making Railway Time table in excel using combo boxes & Text Boxes

    Hellow,
    I am trying to make Railway time table in excel through Visual basic. I have 2 combo Boxes (From and To)& Multiple Text Boxes to populate Train No, Train Name, Arrival & departure (TextBox 1-2-3-4) respectively. When I select Combo box 1 & 2, data is populated in all cited 4 text box correctly(1-2-3-4). But in text box no. 5-6-7-8/9-10-11-12 etc are also populated the same data as appear in text box no 1-2-3-4. Coding which I create is as below.

    Code:
    'Get Items to ComboBox2 based on ComboBox1 selection
    Private Sub ComboBox1_Change()
    
        'Variable Declaration
        Dim iCnt As Integer
        
        'Clear Combobox2 before loading items
        ComboBox2.Clear
     
        With ComboBox2
            Select Case ComboBox1
                Case "Nagpur"
                    .AddItem "Ambala"
                    .AddItem "Amgaon"
                    .AddItem "Agra Cantt"
                    .AddItem "Amravati"
                    .AddItem "BADNERA JN"
                    .AddItem "BADSHAHNAGAR"
                    .AddItem "BADSHAHNAGAR"
                    .AddItem "BAGBAHRA"
    
            End Select
        End With
    
    End Sub
    
    'Get Train No based on ComboBox2 selection
    Private Sub ComboBox2_Change()
        
        'Variable Declaration
        Dim iRow As Integer
        iRow = 3
        
        'Clear Combobox2 before loading items
        TextBox1.Text = ""
        
        'Get Train No based on ComboBox2 selection
        Do
            iRow = iRow + 1
        Loop Until ComboBox2.Text = Sheets("Data").Cells(iRow, 3)
        TextBox1.Text = Sheets("Data").Cells(iRow, 4)
        TextBox2.Text = Sheets("Data").Cells(iRow, 5)
        TextBox3.Text = Sheets("Data").Cells(iRow, 6)
        TextBox4.Text = Sheets("Data").Cells(iRow, 7)
        TextBox5.Text = Sheets("Data").Cells(iRow, 4)
        TextBox6.Text = Sheets("Data").Cells(iRow, 5)
        TextBox7.Text = Sheets("Data").Cells(iRow, 6)
        TextBox8.Text = Sheets("Data").Cells(iRow, 7)
        
    End Sub
    Private Sub TextBox1_Change()
    End Sub
    Private Sub TextBox2_Change()
    End Sub
    Private Sub TextBox3_Change()
    End Sub
    Private Sub TextBox4_Change()
    End Sub
    Private Sub TextBox5_Change()
    End Sub
    Private Sub TextBox6_Change()
    End Sub
    Private Sub TextBox7_Chnge()
    End Sub
    Private Sub TextBox8_Change()
    End
    Request you kindly help. Thanks for your active co-operation.
    Regards,
    Bhawesh
    Last edited by Rabbit; Dec 17 '14, 05:44 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    Bhawesh,

    Lines 45-48 of your code block above is assigning the values from Columns 4-7 (which are the same values assigned to Text Boxes 1-4). Perhaps you meant to assign columns 8-11?

    Also, I see no references in your Code to Text Boxes 9-12, so I am not sure how they are getting updated.

    Just as a side note, Lines 11-22 could get quite cumbersome as you add more and more Departure/Destination cities. Have you thought of having this data elsewhere on the Spreadsheet?

    Better yet, have you thought of creating an MS Access Database? (yeah, that's just a personal plug, since that is more of my forte)

    Comment

    Working...