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

LIST TABLES N DATABASE(COMBO BOX) 7

Status
Not open for further replies.

villica

Programmer
Feb 25, 2000
332
CA
I have a list of Logs tables on my database. They only contain date, actvity and what a person did on that certain date and the time spent. I would like to have a form that list the log tables on a list box or combo box. I would like the user to pick the table they want and then generate a cross tab report from. I have not figure out the report yet but I am hopping at least to be able to display the tables. I am not sure what is the best way of doing this, but any suggestions would be appreciated.<br>
Thank You<br>
<p>Villica<br><a href=mailto:villica67@hotmail.com>villica67@hotmail.com</a><br><a href= > </a><br>
 
Here's one approach: If your log tables have a certain string in common, such as tblLog*, you could create a combo box with a source query that looks for that string in the MSysObjects table (Name column). Then add a button to the form that uses the value in the combo box as a parameter in the DoCmd.Open command. Use the button wizard to create the code for you, then modify it as needed.
 
Here is a good staring point<br>
this code will debug.print all of the tables out<br>
--------------------------<br>
Public Sub TableDefs()<br>
On Error GoTo Err_TableDefs<br>
Dim dbs As Database<br>
Dim tdfNew As TableDef<br>
Dim tdfLoop As TableDef<br>
Dim prpLoop As Property<br>
<br>
Set dbs = CurrentDb<br>
' Create new TableDef object, append Field objects<br>
' to its Fields collection, and append TableDef<br>
' object to the TableDefs collection of the<br>
' Database object.<br>
Set tdfNew = dbs.CreateTableDef(&quot;NewTableDef&quot;)<br>
tdfNew.Fields.Append tdfNew.CreateField(&quot;Date&quot;, dbDate)<br>
<br>
dbs.TableDefs.Append tdfNew<br>
<br>
With dbs<br>
Debug.Print .TableDefs.Count & _<br>
&quot; TableDefs in &quot; & .Name<br>
<br>
' Enumerate TableDefs collection.<br>
For Each tdfLoop In .TableDefs<br>
<br>
If Left(tdfLoop.Name, 4) = &quot;MSys&quot; Or Left(tdfLoop.Name, 1) = &quot;~&quot; Then<br>
'leave it out of the list<br>
Else<br>
'print out tables<br>
Debug.Print &quot; &quot; & tdfLoop.Name<br>
<br>
End If<br>
Next tdfLoop<br>
<br>
.Close<br>
End With<br>
<br>
Exit_TableDefs:<br>
Exit Sub<br>
<br>
Err_TableDefs:<br>
Select Case Err.Number<br>
Case 3010<br>
'Table already exists<br>
DoCmd.DeleteObject acTable, &quot;NewTableDef&quot;<br>
Resume Next<br>
Case Else<br>
MsgBox &quot;Error # &quot; & Err.Number & &quot; &quot; & Err.Description, vbInformation, &quot;In sub TableDefs&quot;<br>
Resume Exit_TableDefs<br>
End Select<br>
End Sub<br>
---------------------------------- <p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
Hi,<br>
When querying MSysObjects table remember that the type code for tables is &quot;1&quot; - last field of table.<br>
Mike
 
I have a problem. I am very new to Access so the above reply I was not able to figure out in its entirety.<br>
Elizabeth all my logs starts with: logmmm00(EG LOGMAY99)<br>
I am not quite sure what do you mean by a source query using mSysObject. I looked in the help but I was not able to find anythig.<br>
<br>
Doug If I were to use some of the code you gave me. Do I put it under the combo box or do I create a button.<br>
<br>
Thank you all for your help.<br>
<br>
<p>Villica<br><a href=mailto:villica67@hotmail.com>villica67@hotmail.com</a><br><a href= > </a><br>
 
OK here it is ready to go, tested and debugged...<br>
<br>
------------------------ Put this in your On_load event of the form<br>
Private Sub Form_Current()<br>
On Error GoTo Err_TableDefs<br>
Dim dbs As Database<br>
Dim tdfNew As TableDef<br>
Dim tdfLoop As TableDef<br>
Dim prpLoop As Property<br>
Dim ComboRow As String<br>
Set dbs = CurrentDb<br>
' Create new TableDef object, append Field objects<br>
' to its Fields collection, and append TableDef<br>
' object to the TableDefs collection of the<br>
' Database object.<br>
Set tdfNew = dbs.CreateTableDef(&quot;NewTableDef&quot;)<br>
tdfNew.Fields.Append tdfNew.CreateField(&quot;Date&quot;, dbDate)<br>
<br>
dbs.TableDefs.Append tdfNew<br>
<br>
With dbs<br>
Debug.Print .TableDefs.Count & _<br>
&quot; TableDefs in &quot; & .Name<br>
ComboRow = &quot;&quot;<br>
' Enumerate TableDefs collection.<br>
For Each tdfLoop In .TableDefs<br>
<br>
If Left(tdfLoop.Name, 3) = &quot;LOG&quot; Then<br>
'Add to combo box<br>
Debug.Print &quot; &quot; & tdfLoop.Name<br>
ComboRow = ComboRow & Chr$(34) & tdfLoop.Name & &quot;&quot;&quot;;&quot;<br>
End If<br>
<br>
Next tdfLoop<br>
Me!Combo2.RowSource = Left(ComboRow, Len(ComboRow) - 1)<br>
.Close<br>
End With<br>
<br>
Exit_TableDefs:<br>
Exit Sub<br>
<br>
Err_TableDefs:<br>
Select Case Err.Number<br>
Case 3010<br>
'Table already exists<br>
DoCmd.DeleteObject acTable, &quot;NewTableDef&quot;<br>
Resume Next<br>
Case Else<br>
MsgBox &quot;Error # &quot; & Err.Number & &quot; &quot; & Err.Description, vbInformation, &quot;In sub TableDefs&quot;<br>
Resume Exit_TableDefs<br>
End Select<br>
<br>
End Sub<br>
<br>
<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
villica,<br>
Put this in your combobox row source:<br>
<br>
<br>
Select Name from MsysObjects where Name like &quot;log*&quot; And Type in(4,6,1)<br>
4 = ODBC tables<br>
6 = ISAM attached tables<br>
1 = Local access tables<br>
<br>
--Jim Horton
 
Jim,<br>
I can't get that to work in Access '97<br>
But it sure is 500% shorter than my Ruug Goldberg Approach. <p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
Doug<br>
I just pasted directly from the post, (but I took out the Like log* clause-- that was for villica's case), and it worked. (obviously don't include the 3 lines explaining what number goes to what type of table).<br>
--Jim<br>

 
Well I created 3 tables - LOGjun99,LOGjul99 and LOGaug99 just for testing and it still does not work.<br>
The odd thing is when I click the combo box it will drop down with 3 items cause I have 3 tables but all 3 items are blank. Nothing shows in them.<br>
This is a brand new install of Office '97 Pro.<br>
Do I need to check on something.<br>
This is a brand new computer 3 days old.<br>
I just built my self a new Windows 2000 Pro machine from scratch.<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
I found the problem<br>
I originally set up the combo box using the &quot;Wizard&quot;.<br>
I picked two fields out of a random table<br>
the Column widths were set to 0&quot;;1&quot; by the wizard.<br>
So the LOG* info was in column 0 which had no width and did not show.<br>
Nothing was in column 1 so nothing showed there either.<br>
Even though I saw three blank items when I clicked the down arrow.<br>
I set both columns to 1&quot; and<br>
It works now...<br>
<br>
I voted your code a star by the way.<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
Hi Doug thank you for the code but I coul not get it to work, I basically just copy and paste. You told me to put it under the load form event but your code starts with form_current, was this a typo?. I still would like to try it out if you think I put it under the wrong event..<br>
<br>
Jim your code works perfect and it works great. Thank you so very much both of you for your wonderfull help. I also gave you a start.<br>
<br>
<br>
Thank you again<br>
<br>
<p>Villica<br><a href=mailto:villica67@hotmail.com>villica67@hotmail.com</a><br><a href= > </a><br>
 
Yes and NO<br>
I said under Form Load but though about it while I was creating it.<br>
It will work under either.<br>
If you put it under the Form load event it will work only the first time you open the form. (thus On_load)<br>
So If you move to the next record and some new table is added, it will not update the data in the combo box<br>
The best place to put it is the On-Current event.<br>
The ON-current event is tripped when the form opens and also moving around in the recordset.<br>
I'm not sure why it does not work.<br>
Are getting an error<br>
Frankly I would'nt worry about it.<br>
You have a much better solution in Jim's<br>
<p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
If you click on Tools/Objects/View and check &quot;System Objects&quot;, you will see some system tables that are normally hidden. One of these, MSysObjects, lists all the objects in the Database, including the tables. The names are listed in the Names columns, and as MikeAngelastro noted, in case you have other objects with similar names, you can also chaeck that the object Type in the Type column is &quot;1&quot; for table. You can use table as a source for a query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top