Fill Combo Box With MSACCESS' table column headers

explains how to fill a combo box with the table columns names

Page 1 of 1

1 Replies - 8087 Views - Last Post: 22 November 2009 - 05:25 AM Rate Topic: -----

#1 Guest_evry1falls*


Reputation:

Fill Combo Box With MSACCESS' table column headers

Posted 21 November 2009 - 04:27 PM

Quote

In The Name Of Allah, The Most Gracious, The Most Merciful


Hello Evry1,

Im sure alot of you know this already , but im sure that alot more don't !!
so here is the thing without colors and smiles ....

1- create an ms access database ( " test.mdb " ) ----> or whatever pleases your instincts
2- create table ( " My Test " ) with 5 Columns :
- ID NUMBER int
- Sname text
- Sgae number int
- Sadd text
- Snotes Memo
3- save the table with no primary key, and close the database.
4 - start new vb app with ...
- one form
- one commandbutton
- one combo box
5- GoTo Project=>References=>Choose 'microsoft activeX 2.6' or higher => click "ok"
6- save your project .
7- codes ...................

Option Explicit
Dim CN As New ADODB.Connection		'database connection
Dim RS As New ADODB.Recordset		  'table connection

Private Sub Command1_Click()
'Combo1.AddItem RS.Fields(0).Name
'Combo1.AddItem RS.Fields(1).Name
'Combo1.AddItem RS.Fields(2).Name
'Combo1.AddItem RS.Fields(3).Name
'Combo1.AddItem RS.Fields(4).Name
'But Instead of doing this ,,, you can simply do this ....
Dim x, t As Integer
x = RS.Fields.Count
For t = 0 To x - 1
Combo1.AddItem RS.Fields(t).Name
Next t
End Sub

Private Sub Form_Load()
CN.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0; DATA SOURCE =" & App.Path & "/TEST.MDB;"
RS.CursorLocation = adUseClient
RS.Open "mYtEST", CN, adOpenDynamic, adLockOptimistic
End Sub


-------------------------------------------------------------------------------------------------------------------------
LOOK :

THE TABLE COLUMNS NAMES ARE AN ARRAY STARTS WITH ( 0 ) .
SO IF THE TABLE HAVE 5 COLUMNS THAT MEANS YOU HAVE AN ARRAY ( 0,1,2,3,4 ) OF 5 ELEMENTS.
-------------------------------------------------------------------------------------------------------------------------

CLICK ON THE COMMAND BUTTON AND THANK ME LATER .....
AS YOU ARE WELCOME ALREADY ....

This post has been edited by evry1falls: 21 November 2009 - 04:28 PM


Is This A Good Question/Topic? 0

Replies To: Fill Combo Box With MSACCESS' table column headers

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Fill Combo Box With MSACCESS' table column headers

Posted 22 November 2009 - 05:25 AM

hi dude :)

you can make a Tutorial or just put it in Share your project forum. i suggest you make tutorial :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1