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, 4 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
-
Oracle kinda-sorta tells customers it was pwned
by
Nibbled To Death By Ducks
4 hours, 56 minutes ago -
Global data centers (AI) are driving a big increase in electricity demand
by
Kathy Stevens
15 hours, 16 minutes ago -
Office apps read-only for family members
by
b
17 hours, 52 minutes ago -
Defunct domain for Microsoft account
by
CWBillow
14 hours, 44 minutes ago -
24H2??
by
CWBillow
4 hours, 55 minutes ago -
W11 23H2 April Updates threw ‘class not registered’
by
WindowsPersister
1 day, 2 hours ago -
Master patch listing for April 8th, 2025
by
Susan Bradley
2 hours, 47 minutes ago -
TotalAV safety warning popup
by
Theodore Nicholson
14 hours, 40 minutes ago -
two pages side by side land scape
by
marc
2 days, 15 hours ago -
Deleting obsolete OneNote notebooks
by
afillat
2 days, 17 hours ago -
Word/Outlook 2024 vs Dragon Professional 16
by
Kathy Stevens
1 day, 20 hours ago -
Security Essentials or Defender?
by
MalcolmP
1 day, 23 hours ago -
April 2025 updates out
by
Susan Bradley
4 hours, 23 minutes ago -
Framework to stop selling some PCs in the US due to new tariffs
by
Alex5723
1 day, 16 hours ago -
WARNING about Nvidia driver version 572.83 and 4000/5000 series cards
by
Bob99
1 day, 6 hours ago -
Creating an Index in Word 365
by
CWBillow
2 days, 9 hours ago -
Coming at Word 365 and Table of Contents
by
CWBillow
21 hours, 24 minutes ago -
Windows 11 Insider Preview Build 22635.5170 (23H2) released to BETA
by
joep517
3 days, 12 hours ago -
Has the Microsoft Account Sharing Problem Been Fixed?
by
jknauth
3 days, 16 hours ago -
W11 24H2 – Susan Bradley
by
G Pickerell
3 days, 18 hours ago -
7 tips to get the most out of Windows 11
by
Alex5723
3 days, 16 hours ago -
Using Office apps with non-Microsoft cloud services
by
Peter Deegan
3 days, 9 hours ago -
I installed Windows 11 24H2
by
Will Fastie
1 day, 15 hours ago -
NotifyIcons — Put that System tray to work!
by
Deanna McElveen
3 days, 21 hours ago -
Decisions to be made before moving to Windows 11
by
Susan Bradley
14 hours, 49 minutes ago -
Port of Seattle says ransomware breach impacts 90,000 people
by
Nibbled To Death By Ducks
4 days, 5 hours ago -
Looking for personal finance software with budgeting capabilities
by
cellsee6
3 days, 13 hours ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
3 days, 14 hours ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
4 days, 22 hours ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
5 days, 7 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.