tables names to combobox list

J

John Coon

Group,

I need some help with the display of tables names being displayed in a
combobox.
after connecting to the database I need to collect the names to the tables
available to me. this is where I'm having trouble. it reads the table names
but it displays
the table names on one line like
ex: sign, light,drainage, marking

I want the combobox to display like cascade down
sign
light
drainage
marking

Also I'd great appreciate any links that show how to use listview to dispay
the fields avaiable in the table that I can use a checkbox to select items
to label
in a autocad drawing

Have a great day
John


'sample I'm using
Dim wksObj As Workspace
Dim dbsObj As Database
Dim tblObj As TableDef
Dim fldObj As Field
Dim rstObj As Recordset
Dim reccount As Integer

Set wksObj = DBEngine.Workspaces(0)

On Error Resume Next
Set dbsObj = DBEngine.Workspaces(0).OpenDatabase(TextBox2.Text)

Dim strTableItem As String
Dim strValueList As String
Dim intCounter As Integer

For Each tblObj In dbsObj.TableDefs
intCounter = 1
If Left(tblObj.Name, 4) <> "MSys" Then
strTableItem = tblObj.Name
strTableItem = strTableItem & " "
intCounter = intCounter + 1
If intCounter > 1 Then
strValueList = strValueList & strTableItem
Debug.Print strValueList
End If
End If
Next

UserForm1.ComboBox1.AddItem strValueList
UserForm1.ComboBox1 = strValueList
 
A

Allen Browne

To show a list of tables, create this query and use it as the RowSource of
your combo:
SELECT MsysObjects.Name FROM MsysObjects
WHERE (([Type] IN (1,4,6) AND ([Name] Not Like "~*")
AND ([Name] Not Like "MSys*"))
ORDER BY MsysObjects.Name;

To show the fields of a particular table, set the combo's Row Source Type
to:
Field List
and put the table name in the Row Source property.

In the more recent versions of Access, it is also possible to use DAO code
like you suggeted to AddItem to the combo, but you don't really need code.
 
J

John Coon

Alien,

Thank you for your reply I'm only using access as a container, my form is in
an AutoCAD program where I browse to a access db and have several tables
in the db and want to select with one to use to populate the cad drawing
with. with that in mind do I still need to access the field names as you
described.

Have a great day
John




Allen Browne said:
To show a list of tables, create this query and use it as the RowSource of
your combo:
SELECT MsysObjects.Name FROM MsysObjects
WHERE (([Type] IN (1,4,6) AND ([Name] Not Like "~*")
AND ([Name] Not Like "MSys*"))
ORDER BY MsysObjects.Name;

To show the fields of a particular table, set the combo's Row Source Type
to:
Field List
and put the table name in the Row Source property.

In the more recent versions of Access, it is also possible to use DAO code
like you suggeted to AddItem to the combo, but you don't really need code.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

John Coon said:
Group,

I need some help with the display of tables names being displayed in a
combobox.
after connecting to the database I need to collect the names to the
tables available to me. this is where I'm having trouble. it reads the
table names but it displays
the table names on one line like
ex: sign, light,drainage, marking

I want the combobox to display like cascade down
sign
light
drainage
marking

Also I'd great appreciate any links that show how to use listview to
dispay the fields avaiable in the table that I can use a checkbox to
select items to label
in a autocad drawing

Have a great day
John


'sample I'm using
Dim wksObj As Workspace
Dim dbsObj As Database
Dim tblObj As TableDef
Dim fldObj As Field
Dim rstObj As Recordset
Dim reccount As Integer

Set wksObj = DBEngine.Workspaces(0)

On Error Resume Next
Set dbsObj = DBEngine.Workspaces(0).OpenDatabase(TextBox2.Text)

Dim strTableItem As String
Dim strValueList As String
Dim intCounter As Integer

For Each tblObj In dbsObj.TableDefs
intCounter = 1
If Left(tblObj.Name, 4) <> "MSys" Then
strTableItem = tblObj.Name
strTableItem = strTableItem & " "
intCounter = intCounter + 1
If intCounter > 1 Then
strValueList = strValueList & strTableItem
Debug.Print strValueList
End If
End If
Next

UserForm1.ComboBox1.AddItem strValueList
UserForm1.ComboBox1 = strValueList
 
A

Allen Browne

I doubt that AutoCAD has the capacity to set combos that way.

If you are able to add a reference to the DAO library in your AutoCAD
application, you could programmatically loop the Fields of the TableDef. The
VBA code to do that is illustrated here:
http://allenbrowne.com/func-06.html
 
J

John Coon

Allen,

Thank you for your help/comments.
I can add the DAO in AutoCAD so I'll try as you suggested.
again thank you
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top