Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW TO FILL A DROPDOWN LIST WITH DB TABLE NAMES 2

Status
Not open for further replies.

jflo

Programmer
Mar 13, 2001
44
CA
I'm looking for a way to create a dropdown list that contains all the table names from my db.

J-F
 
Hi!

Maybe is better solution, I don't know, but you can try it:

Private Sub Form_Load()
Me.lstTables.RowSource = TdfList
End Sub

Function TdfList() As String
Dim tdf As TableDef

For Each tdf In CurrentDb.TableDefs
If Left(tdf.Name, 4) <> &quot;MSys&quot; Then 'Access system tables
If TdfList <> &quot;&quot; Then
TdfList = TdfList & &quot;;&quot;
End If
TdfList = TdfList & &quot;'&quot; & tdf.Name & &quot;'&quot;
End If
Next tdf
End Function

Aivars
 
You can use this query also:

SELECT MSysObjects.Name, MSysObjects.Type FROM MSysObjects
WHERE ((MSysObjects.Type)=6);
Mike Rohde
rohdem@marshallengines.com
 
Aivars --> Thanks. Somehow the only result I could get with your function was a combobox with a string maide of the table names separated by &quot;;&quot;. I played around with it a bit and could not figure out how to correctly fill my combobox with it. If you know why and how, let me know.

Mike --> Why (MSysObjects.Type)=6? This didn't return any value. When I removed the criteria, I could see all the entries in MSysObjects. There are no type 6. I used type 1 and supplied a criteria in name cause all my table starts with T as in TEmployee. So I used &quot;T*&quot; as criteria combined with 1 in the type and it works. Thanks
 
You are right. Type 1 is a table, type 6 is a linked table. Thank God its Friday......... :p Mike Rohde
rohdem@marshallengines.com
 
Here's my variation (I use it to show all tables, queries, & reports so you can tweak it for tables):

SELECT MSysObjects.Id, MSysObjects.Name
FROM MSysObjects
WHERE (((MSysObjects.Name) Not Like &quot;~*&quot; And (MSysObjects.Name) Not Like &quot;msys*&quot; And (MSysObjects.Name) Not Like &quot;{*&quot;))
ORDER BY MSysObjects.Name;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top