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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting a DB Table Name ? 1

Status
Not open for further replies.

londonkiwi

Programmer
Sep 25, 2000
83
0
0
NZ
I am developing a programme that will export a txt file to a specified Access DB Table (VB 5)

I have a combo box cboTables, which grabs all the Tables in the selected Database.

The code for this is below. Once the appropriate table (to put the parsed txt data in) is selected, I want to get that table path and name eg c:/mystuff/newdb.mdb/TheTable
I want to a) write to this table b) put the path in a listbox, so the user can see which one they've chosen.

....
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(gf_strDbpath)

cboTables.Clear

For i% = 0 To db.TableDefs.Count - 1
strTblName = dbTableDefs(i%).Name
cboTables.AddItem strTblName
Next i%
....


Thanks in advance
 
What is table path "c:/mystuff/newdb.mdb/TheTable
"? This is not how you place information into a DB.
 
Ok, the users first selects the DB (gf_strDBName) via the common dialog, then is allowed to choose a table from that DB (via cboTables). I want to get the name of the DB table they have selected, and write data to it from a ttx file.

So how do you do it??

Thanks in advance
 
Use this:

Dim db as Database
Dim rs as Recordset
Dim sql as String
Set db = OpenDatabase("c:/mystuff/newdb.mdb")

sql = "SELECT * FROM CAT;"

Set rs = db.OpenRecordset(sql)

place code to dispay items

rs.MoveNext

rs.close
db.close


 
Thanks.

i take it that in the following "SELECT * FROM CAT;"

CAT is the Table name. If so, how do I check the cbTable combo box for the Table that the user has selected?

Sorry if i have missed the point! (you may have made above)
 
You enumerate the table names via the TableDefs collection. For each .Name you populate the combo box and then you get the selected item by just assigning a string variable to the (default property) of the combo box.

Here is an example of the enumeration from the DAO Help examples:

This example creates a new TableDef object and appends it to the TableDefs collection of the Northwind Database object. It then enumerates the TableDefs collection and the Properties collection of the new TableDef.

Sub TableDefX()

Dim dbsNorthwind As Database
Dim tdfNew As TableDef
Dim tdfLoop As TableDef
Dim prpLoop As Property

Set dbsNorthwind = OpenDatabase("Northwind.mdb")

' Create new TableDef object, append Field objects
' to its Fields collection, and append TableDef
' object to the TableDefs collection of the
' Database object.
Set tdfNew = dbsNorthwind.CreateTableDef("NewTableDef")
tdfNew.Fields.Append tdfNew.CreateField("Date", dbDate)

dbsNorthwind.TableDefs.Append tdfNew

With dbsNorthwind
Debug.Print .TableDefs.Count & _
" TableDefs in " & .Name

' Enumerate TableDefs collection.
For Each tdfLoop In .TableDefs
Debug.Print " " & tdfLoop.Name
Next tdfLoop

With tdfNew
Debug.Print "Properties of " & .Name

' Enumerate Properties collection of new
' TableDef object, only printing properties
' with non-empty values.

For Each prpLoop In .Properties
Debug.Print " " & prpLoop.Name & " - " & _
IIf(prpLoop = "", "[empty]", prpLoop)
Next prpLoop

End With

' Delete new TableDef since this is a
' demonstration.
.TableDefs.Delete tdfNew.Name
.Close
End With

End Sub
 
Hey Koala,

Could you take a look at this new thread:

Problem Deleting Actual Attached Tables
thread181-174976

Looks like you have experience with TableDefs.Delete and your opinion would be appreciated.

Thanks,
Brooks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top