Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 1st, 2004, 10:10 AM
Authorized User
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Populate combo box with access db with using ADO

I am very new to making VB applications although I have a fair amount of experience with ASP. I want to populate a dropdown combo box with all the users in my database which is situated in the same directory as the application.

I am unsure of the coding but I would assume that you would have to locate the db like:

App.Path & "\despatcher97.mdb"

and the SQL statement would be as follows:

strSQL = "select * from Users order by Name"

and with my experience with ASP I assume the population part would be something like:

    Combo1.AddItem .Fields("Username").Value
    Combo1.ItemData(Combo1.NewIndex) = .Fields("Ident").Value
  Loop Until .EOF

I am just unsure how you would fit it all together.
Any help with this matter would be greatly received.

With many thanks for your time and assistance,

Old September 28th, 2004, 02:07 AM
Friend of Wrox
Join Date: Sep 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma

Well friend u r going very correct.

Its better to use DSN to connect to mdb file. It gives the freedom to keep ur mdb file anywhere in network and locate the database through DSN. If r not aware of DSNs, see in Win 2000 help "creating DSN".
If u r using connectionstring ("Provider=Microsoft.jet.7.0,database=......). U have to provide the path of mdb file in the way u have mentioned.

Public Sub FillCombo()
 dim Rs as New ADODB.RecordSet
 Set Rs = Conn.Execute("Select Name From Users Order by name")
    Do while Rs.Eof()=False
       Combo1.AddItem Rs("Name") & ""
    Set Rs = Nothing
End Sub

Hope this helps.

B. Anant

Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate a text box from a combo box value dnf999 Access VBA 7 February 6th, 2012 02:24 PM
Populate Combo Box phil.t Access 3 November 18th, 2004 03:39 AM
Populate combo box with access db with using ADO neo_jakey Pro VB Databases 1 October 23rd, 2004 10:11 AM
Populate combo box with access db with using ADO neo_jakey VB Databases Basics 3 October 13th, 2004 03:36 PM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.