Select DataBase using ComboBox

databases Taiping, Malaysia
  • 14 years ago

    Hi., every one.

    I want to know , how to write code for pickup data from access database to my form using combobox and display all data into textbox, follow the combobox selection.

    i'am using 1 combox and 32 textbox

    all data must display in textbox when i select (change) at combobox ( by company names )


    my example programs :


    Option Explicit
    Dim DB As Database
    Dim RS As Recordset
    Dim Data As String

    Private Sub Form_Load()
    CustData.DatabaseName = App.Path & "\CIS Database.mdb"
    CustData.RecordSource = "CISData"
    Set DB = OpenDatabase(App.Path & "\CIS Database.mdb") 'Open database
    Set RS = DB.OpenRecordset("SELECT * FROM CISData") '  ORDER BY Company") 'Choose the table
    Do While RS.EOF <> True 'add all the items in combobox
    Combo1.AddItem RS(2) '& ""

    Label11.Caption = frmLogin.txtUserName
    Label13.Caption = Date
    Label13.Caption = Format(Date, "dd MMMM yyyy")

    End sub


    Private Sub Combo1_Click()
    On Error Resume Next


    What coding i must write here...?


    please help...



  • 14 years ago
    Maybe something like this:

    Private Sub Combo1_Click()
    Set RS = DB.OpenRecordset("SELECT * FROM CISData WHERE Company = '" & Combo1.Text & "'")
        If RS.EOF = False Then
            Text1.Text = RS(1)
            Text2.Text = RS(2)
            Text32.Text = RS(32)
        End If
    End Sub

    I hope this helps... Smiley Face [:)]

  • 14 years ago
    Thanks a lot.... very helpfull.... Smiley Face [:)]
  • 14 years ago

    Please help me again....

    Some error come out. When i select with combox list and need to addnew record, i just can write at textbox but cannot save to database.

    That's means no new record added.

    how to resolve this problems   same when i need to edit record.  




  • 13 years ago


    Use form's activate event not a load event. May this would help you. For complete answer send me the code. 





Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.”