Results 1 to 4 of 4

Thread: Combo Box Dilema

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    Greenville
    Posts
    73

    Post

    I am trying to connect this combo box with textboxes so that when something is selected then its info will be filled in the textboxes, Easy. OK well my text boxes are not changing with my diff selections. I included a piece of code below to show what I have. I also am trying to include an SQL statement somewhere that when say the Name is selected from the combo box it hooks to the indexID in its table that is apart of its relations to other tables. Any further suggestions on any of the above. Thankyou.


    Private Sub cboAuctions_Change()
    Dim db As Database
    Dim tb11 As Recordset
    Set db = DBEngine.OpenDatabase("S:\Dbapps\Repo\RepoInv", False, False)

    Set tb11 = db.OpenRecordset("Auctions")

    If tb11.RecordCount > 0 Then
    tb11.Edit
    tb11!Auctions = cboAuctions.Text
    tb11.Update
    Else
    MsgBox "No record Found"
    End If

    ' Fill in textboxes with info that matches selection
    If IsNull(tb11!AuctionAddress) = True Then
    txtActnAddrss.ForeColor = vbRed
    txtActnAddrss = "Input"
    Else
    txtActnAddrss.ForeColor = vbBlack
    txtActnAddrss.Text = tb11!AuctionAddress
    End If
    tb11.Close
    db.Close
    End Sub

  2. #2
    New Member
    Join Date
    Jan 2000
    Location
    Toronto,Canada
    Posts
    7

    Post




    Private Sub cboAuctions_Change()
    Dim db As Database
    Dim tb11 As Recordset
    Set db = DBEngine.OpenDatabase("S:\Dbapps\Repo\RepoInv", False, False)

    Set tb11 = db.OpenRecordset("Auctions")

    If tb11.RecordCount > 0 Then
    tb11.Edit
    tb11!Auctions = cboAuctions.Text
    tb11.Update
    Else
    MsgBox "No record Found"
    End If

    ' Fill in textboxes with info that matches selection
    If IsNull(tb11!AuctionAddress) = True Then
    txtActnAddrss.ForeColor = vbRed
    txtActnAddrss = "Input"
    Else
    txtActnAddrss.ForeColor = vbBlack
    txtActnAddrss.Text = tb11!AuctionAddress
    End If
    tb11.Close
    db.Close
    End Sub[/B][/QUOTE]

    make sure your combobox's source is an sql
    statement that includes the fields you want toshow in the text boxes.
    ie
    select id,name,address

    text1.text=combo1.columns(1) ' name
    text2.text=combo1.columns(2) ' address

    try that

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    Greenville
    Posts
    73

    Post

    I am trying to put the following SQL in that I inserted below but it is not even filling or connecting to the text boxes (using the rest of the code I sent before). When I stick all of the ifNull stuff under the 'Change' event it does not fill in but when I seperate it and put the ifNull stuff under the 'click' event then it just fills in that one record of info. I know this has got to be easy but it is just not happenin'. Tell me is I need to clarify anymore.

    Dim db As Database
    Dim tb11 As Recordset
    Dim Sql As String
    Sql = "Select * from Auctions"
    Set db = DBEngine.OpenDatabase("S:\Dbapps\Repo\RepoInv", False, False)
    Set tb11 = db.OpenRecordset("Auctions")

  4. #4
    New Member
    Join Date
    Feb 2000
    Posts
    5

    Post

    If I'm understanding you correctly, you have a combo box that list items and when that
    item is clicked you want to display all the
    information for that item in the text box.

    Lets say your have 3 records the first
    record has the ID number, the second record
    has the Name and the third record has the
    description.

    The first step would be to load all the ID's
    in the combo at from load.

    Private Sub Form_Load()
    Dim db As Database
    Dim rs As RecordSet

    Set db =OpenDatabase(App.Path &"\dbname.mdb")
    Set rs = db.OpenRecordset("TableName")

    Do While Not rs.EOF
    combo1.AddItem rs("ID")
    rs.MoveNext
    Loop
    rs.Sort = "ID"
    rs.Close
    db.Close
    End Sub

    The code below would enter the users selection in to the text boxes.

    Private Sub combo1_Click()
    Dim db As Database
    Dim rs As RecordSet
    Dim sql As String

    sql = "Select * From TableName Where ID =' "
    & combo1.Text & " ' "

    Set db=OpenDatabase(App.Path &"\dbname.mdb")
    Set rs=db.OpenRecordset(sql)

    txtID = rs("ID")
    txtName = rs("Name")
    txtDes= rs("Des")

    rs.close
    db.close

    End Sub

    [This message has been edited by etta (edited 02-05-2000).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width