i’m making an app in vb6 with an access 97 back end i want to have a combo box on the form and when someone clicks in the combo box the form is updated to the combo selection
i can do this in access but don’t know how in vb
any help greatly appreciated
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
combo box in vb (vb6 access 97)
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » combo box in vb (vb6 access 97)
- This topic has 4 replies, 3 voices, and was last updated 23 years, 7 months ago.
AuthorTopicWSJerryC
AskWoody LoungerNovember 15, 2001 at 9:23 pm #362928Viewing 2 reply threadsAuthorReplies-
WScharlotte
AskWoody LoungerNovember 16, 2001 at 2:42 am #552439I don’t. I refuse to do stuff like that in VB because it’s so much harder than in Access. The functionality for populating the comboboxes has to be built in code in VB and you have to create your own secondary indexes.
If you feel you must, there are several very good books on building database applications with VB.
-
WSDottie
AskWoody LoungerNovember 19, 2001 at 3:33 am #552830Jerry,
If you still want to do this in VB here are a few things that might give you some ideas. This example populates the combo box with CompanyName from the Customers table of Northwind. When a user clicks on a name, a couple of textboxes will be populated with data for that customer:
In general declarations of the form: Dim cnNorthWind as ADODB.Connection
Then load the combobox when the form loads, limiting the recordset to one field
Private Sub Form_Load()
‘ Establish a connection to the Access database
Set cnNorthwind = New ADODB.Connection
With cnNorthwind
.Provider = “Microsoft.Jet.OLEDB.4.0”
.ConnectionString = “Data Source=C:Program FilesMicrosoft Visual StudioVB98Nwind.mdb;Persist Security Info=False”
.Open
End With
‘
Dim rsCustomers As ADODB.Recordset
Set rsCustomers = New ADODB.Recordset
rsCustomers.ActiveConnection = cnNorthwind
rsCustomers.Open “Select CompanyName from Customers”
Do Until rsCustomers.EOF
cboNames.AddItem rsCustomers!CompanyName
rsCustomers.MoveNext
Loop
‘ might as well free up the memory
rsCustomers.Close
Set rsCustomers = Nothing
End SubIn the ComboBox’s Click event, go get the data matching the selected item; this example keeps it simple by querying the same table, but of course you could build a more complex SQL statement with joins and stuff – use Access QBE to do it and paste the SQL view from Access into your code.
Private Sub cboNames_Click()
‘Purpose: Retrieve values for the selected customer
Dim strSQL As String
Set rsCustInfo = New ADODB.Recordset
‘ Use the connection already opened in Form’s Load event
rsCustInfo.ActiveConnection = cnNorthwind‘ Choose the appropriate cursor and locks for your project
rsCustInfo.CursorType = adOpenStatic
rsCustInfo.LockType = adLockOptimistic‘Note: The concatenation here is not the most robust! Needs improvement
‘ The SQL statement will have syntax errors if there are embedded quotes in cboNames.textstrSQL = “Select City, ContactName FROM Customers WHERE CompanyName = ‘” & cboNames.Text & “‘”
rsCustInfo.Open strSQL‘ If you want to bind the fields to controls on the form
Set txtCity.DataSource = rsCustInfo
txtCity.DataField = “City”
Set txtContact.DataSource = rsCustInfo
txtContact.DataField = “ContactName”
End Sub
Note: If you only want to show the data and not allow changes use this instead of the datasource and datafield properties.
txtCity.Text = rsCustInfo!City
txtContact.Text = rsCustInfo!ContactNameThere’s lots more to consider; you’ll need to add code to do updates of the recordset if needed, and decide the best way to handle connections and queries. If there aren’t tons of records you might want to retrieve all the data in the Load event such as:
rsCustomers.Open “Select CompanyName, ContactName, City from Customers”
You’d still populate the combobox from the CompanyName field; then in the combobox click event you can just apply a filter instead of running another query against the database:
rsCustomers.Filter = “CompanyName = ‘” & cboNames.Text & “‘” -
WSDottie
AskWoody LoungerNovember 19, 2001 at 4:13 am #552831Just wanted to add that I am not at all disagreeing with Charlotte’s suggestion of a good VB Database book to learn about all the issues involved when manipulating databases through VB. There are lots of details that Access handles so well that need to be addressed with code in VB. But sometimes it is kind of fun to do things the hard way.
-
WScharlotte
AskWoody LoungerNovember 19, 2001 at 5:56 am #552835On the other hand, if you want an outstanding book and doing it with VB, take a look at “Database Access with Visual Basic 6”, by Jeffrey P. McManus. His is the only book I’ve ever found that described the use of classes and the reasons for them in practical, business-oriented ways that the uninitiated could understand. I intend to recommend it to my boss, who can’t see any purpose to class modules in Access. McManus’s chapter on classes is outstanding and most of his stuff translates fairly easily to Access as well The rest of it gets down to the details of using VB to front-end a database clearly and concisely.
-
Viewing 2 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Windows Spotlight broken on Enterprise and Pro for Workstations?
by
steeviebops
1 hour, 51 minutes ago -
Denmark wants to dump Microsoft for Linux + LibreOffice
by
Alex5723
3 hours, 18 minutes ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
2 hours, 28 minutes ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
12 hours, 37 minutes ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
13 hours, 42 minutes ago -
Disengage Bitlocker
by
CWBillow
3 hours, 40 minutes ago -
Mac Mini M2 Service Program for No Power Issue
by
Alex5723
15 hours, 42 minutes ago -
New Win 11 Pro Geekom Setup questions
by
Deo
23 minutes ago -
Windows 11 Insider Preview build 26200.5651 released to DEV
by
joep517
22 hours, 58 minutes ago -
Windows 11 Insider Preview build 26120.4441 (24H2) released to BETA
by
joep517
22 hours, 59 minutes ago -
iOS 26,, MacOS 26 : Create your own AI chatbot
by
Alex5723
1 day, 2 hours ago -
New PC transfer program recommendations?
by
DaveBoston
3 hours, 54 minutes ago -
Windows 11 Insider Preview Build 22631.5545 (23H2) released to Release Preview
by
joep517
1 day, 6 hours ago -
Windows 10 Build 19045.6029 (22H2) to Release Preview Channel
by
joep517
1 day, 7 hours ago -
Best tools for upgrading a Windows 10 to an 11
by
Susan Bradley
19 hours, 19 minutes ago -
The end of Windows 10 is approaching, consider Linux and LibreOffice
by
Alex5723
16 hours, 41 minutes ago -
Extended Windows Built-in Disk Cleanup Utility
by
bbearren
8 hours, 16 minutes ago -
Win 11 24H2 June 2025 Update breaks WIFI
by
dportenlanger
2 days, 1 hour ago -
Update from WinPro 10 v. 1511 on T460p?
by
CatoRenasci
23 hours, 53 minutes ago -
System Restore and Updates Paused
by
veteran
2 days, 4 hours ago -
Windows 10/11 clock app
by
Kathy Stevens
1 day, 15 hours ago -
Turn off right-click draw
by
Charles Billow
2 days, 7 hours ago -
Introducing ChromeOS M137 to The Stable Channel
by
Alex5723
2 days, 11 hours ago -
Brian Wilson (The Beach Boys) R.I.P
by
Alex5723
1 day, 5 hours ago -
Master patch listing for June 10, 2025
by
Susan Bradley
2 days, 12 hours ago -
Suggestions for New All in One Printer and a Photo Printer Windows 10
by
Win7and10
1 day, 15 hours ago -
Purchasing New Printer. Uninstall old Printer Software First?
by
Win7and10
2 days, 18 hours ago -
KB5060842 Issue (Minor)
by
AC641
1 day, 6 hours ago -
EchoLeak : Zero Click M365 Copilot leak sensitive information
by
Alex5723
3 days, 1 hour ago -
24H2 may not be offered June updates
by
Susan Bradley
1 day, 18 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.