link between combo box and textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • squrel
    New Member
    • Jan 2008
    • 143

    link between combo box and textbox

    Hi..
    i have a problem here...
    i have a master table called casemaster and in tht i have one combobox called courtId and its filling from the court table.. i need to make a textbox infront of tht and it has to fill the court name from the court table... whenever the user click on the courtid in tht dropdown of combobox tht name of the court automatically has to appear in tht textbox... how can i make a link between the combobox and the textbox... both of them has to be filled from my court table...
    can anyone give me a code sample...
    plz i need a help here and very urgent
    thank u very much
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    you need to pass the court_id from the combo to the db query dunamically and from that fetch the court name.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      You should implement a method that handles the ComboBox's Click Event.
      The Click event occurs whenever the user clicks ComboBox.
      From there you can determine which item has been selected, you can retrieve the court name from the database, and put the court name in the text box.

      Comment

      • squrel
        New Member
        • Jan 2008
        • 143

        #4
        thank u very much for ur help.. bt can u give me any code sample plz
        i wil appricate tht
        thank u in advance

        Comment

        • squrel
          New Member
          • Jan 2008
          • 143

          #5
          ok i m putting this code bt not working and my textbox is empty..
          i dont knw if i m doing rit... when i debug the line which is bold it shows "" and in my textbos it comes 0 ..... where i have to change
          can u help me here plz
          thank u

          Code:
          Private Sub cmbCourtId_Click()
          txtCourtId.Text = GetCorrespodingField("Court", "Courtid", "courtid", cmbCourtId, False)
          Dim cn As String
            If cmbCourtId.Text = true  Then
              'the following line is bold
              cn = Val("select courtname from court where courtid = cmbcourtid.text")'<-----bold line---
              Text1.Text = cn
            End If
          End Sub
          Last edited by Frinavale; Jan 21 '09, 02:08 PM. Reason: added [code] tags

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            i don't understand your code .

            what does GetCorrespoding Field do ?

            Comment

            • squrel
              New Member
              • Jan 2008
              • 143

              #7
              the GetCorrespoding Field is filling the combobox from my court table to my master table... tht is not the problem the if loop is the problem... the line which is bold is coming zero... how can i get the value of courtname in tht line?

              Comment

              • squrel
                New Member
                • Jan 2008
                • 143

                #8
                can anyone check my code and tel me wht changes i have to make in tht line.... need help here

                Comment

                • debasisdas
                  Recognized Expert Expert
                  • Dec 2006
                  • 8119

                  #9
                  try this
                  Code:
                  rs.Open "select court_name from court where court_id = '" & combo1.text & "'", con, adOpenDynamic, adLockOptimistic
                  next populate the textbox from recordset.

                  Comment

                  • squrel
                    New Member
                    • Jan 2008
                    • 143

                    #10
                    i dont think i need to open the rs here... its a simple combo box and textbox... i am changing my code to this bt rhe bold line is telling me "type mismatch"
                    can anyone tel me why?

                    Code:
                    Private Sub cmbCourtId_Click()
                     Dim Rs       As New ADODB.Recordset
                    txtCourtId.Text = GetCorrespodingField("Court", "Courtid", "courtid", cmbCourtId, False)
                    Dim cn As String
                    If cmbCourtId.SelectedIndex <> -1 Then
                    'following line is bold
                    cn = Str("select courtname  from court where courtid = " & cmbcourtid.text)
                    Text1.Text = cn
                    End If
                    End Sub
                    Last edited by Frinavale; Jan 22 '09, 02:08 PM. Reason: added [code] tags

                    Comment

                    • debasisdas
                      Recognized Expert Expert
                      • Dec 2006
                      • 8119

                      #11
                      how have you planned to fetch data from database without opening the recordset ?

                      Comment

                      • squrel
                        New Member
                        • Jan 2008
                        • 143

                        #12
                        if i open the recordset also still i m getting error
                        i did wht u told me to do bt still the text is not showing in my textbox...
                        tht is my problem
                        i opend the recordset as u told me bt the textbox is empty
                        tel me how to get it in the textbox
                        Code:
                        If cmbCourtId.Text <> -1 Then
                        Rs.Open ("select courtname from court where courtid = '" & cmbCourtId.Text & "'"), adOpenDynamic, adLockOptimistic
                        then after tht wht i have to do??? whtever i m doing it tels me type mismatch
                        Last edited by Frinavale; Jan 23 '09, 03:03 PM. Reason: added [code] tags

                        Comment

                        • QVeen72
                          Recognized Expert Top Contributor
                          • Oct 2006
                          • 1445

                          #13
                          Hi,

                          You need to specify Connection object here :

                          Rs.Open ("select courtname from court where courtid = '" & cmbCourtId.Text & "'"), Conn, adOpenDynamic, adLockOptimisti c

                          Regards
                          Veena

                          Comment

                          • squrel
                            New Member
                            • Jan 2008
                            • 143

                            #14
                            Hi Veena,
                            Ok i wil do tht bt then how can i get tht in my textbox?
                            i have combobox called cmbcourtid and by selecting the index from tht i want the particular courtname appear in my textbox called text1 automatically.. i open the connection bt then how i get tht in my textbox?
                            can u help me in tht... whtever i m trying is telling me type mismatch... coz its a string
                            conn i can not put its giving me error as variable not define.. i put Db its working.. and the line after tht when i want to assign tht to a variable to get the courtname on the textbox.. how should it should be??? is my line rit after the rs.open??? i dont knw how it should be?
                            can u help in tht? coz cn is a string
                            thank u

                            Code:
                            Private Sub cmbCourtId_Click()
                            Dim Rs       As New ADODB.Recordset
                            txtCourtId.Text = GetCorrespodingField("Court", "Courtid", "courtid", cmbCourtId, False)
                            Dim cn As String
                            If cmbCourtId.Text <> -1 Then
                            If Rs.State = adStateOpen Then Rs.Close
                            Rs.Open ("select courtname from court where courtid = '" & cmbCourtId.Text & "'"), Db, adOpenDynamic, adLockOptimistic
                            
                            cn = Rs.Fields( ).Value
                            
                            Text1.Text = cn
                            Text1.Refresh
                            End If
                            End Sub

                            Comment

                            • debasisdas
                              Recognized Expert Expert
                              • Dec 2006
                              • 8119

                              #15
                              I think i am wasting my time with you.

                              you seem to lack the basic knowledge of database handling in VB.

                              better you go through the database related articles in the insight section of VIsual Basic for some sample code.

                              Comment

                              Working...