vb6 to access combo box

fill combo box list from access table

Page 1 of 1

3 Replies - 8464 Views - Last Post: 20 June 2010 - 10:58 AM Rate Topic: -----

#1 Guest_dengkee*


Reputation:

vb6 to access combo box

Posted 19 June 2010 - 11:29 PM

hi,

i have 4 combo box from my vb6 form, supplier, destination, material, transport. i would like my form to connect to my access database and display the list through the combo boxes from my table. here is my code below.

Private Sub Form_Load()
Dim deTRATES As Database
Dim rsSUP As Recordset

DoEvents
Dim SATTRIB As String
Dim SDRIVER As String
SATTRIB = "DBQ=H:\CHARGEODBC\TRATES.MDB"
SDRIVER = "MICROSOFT ACCESS DRIVER (*.MDB)"
DBEngine.RegisterDatabase "TRATES", SDRIVER, True, SATTRIB
DoEvents

With deTRATES
    If Not .rsSUP.State = adStateOpen Then 'HERE I HAVE ERROR "METHOD OR DATA MEMEBER NOT FOUND"
            .rsSUP.Open
            End If
End With

End Sub

Private Sub Supplier_GotFocus()
Me.Supplier.Clear
With TRATES.Supplier
        .Sort = "SUPPLIER"
        .MoveFirst
        While Not .EOF
            Me.Supplier.AddItem !Supplier
            .MoveNext
        Wend
End With
DoEvents
End Sub


Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0

Replies To: vb6 to access combo box

#2 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: vb6 to access combo box

Posted 20 June 2010 - 09:19 AM

I am not very knowledgable about VB connections to database, but what looks odd to me is that you declare deTrates and then never set it equal to anything.

This DIC tutorial shows how to connect to SQL db. I am sure could be applied to Access db as well. http://www.dreaminco...se-using-adodb/

This post has been edited by June7: 20 June 2010 - 09:21 AM

Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: vb6 to access combo box

Posted 20 June 2010 - 09:20 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:


  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#4 bytelogik  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 212
  • Joined: 06-October 09

Re: vb6 to access combo box

Posted 20 June 2010 - 10:58 AM

dengkee,

Yes, as June7 suggested you need to point the database variable to your database path
E.g,
Dim dbDef As Database   
Dim rsDef As Recordset  
Set dbDef = DBEngine.OpenDatabase(YourDatabasePath", False, False) 'ex: your databasepath = "c:\something.mdb"
Set rsDef = dbDef.OpenRecordset("select * from yourtable")

'Your database stuff (add/edit/delete/retrieve) here:

'clean up
Set rsDef = Nothing
Set dbDef = Nothing



Hope this helps.

This post has been edited by bytelogik: 20 June 2010 - 10:58 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1