Quote:
|
Originally Posted by rokslide
If you create this function (you might want to tidy it up as it's jsut rough) in your access database...
Code:
Function GetAllTables() As String
'Returns all tables
Dim tmpTables As String
Set db = CurrentDb
db.TableDefs.Refresh
For Each tdf In db.TableDefs
tmpTables = tmpTables & tdf.Name & ","
Next
tmpTables = Left(tmpTables, Len(tmpTables) - 1)
Set collTables = Nothing
Set tdf = Nothing
Set db = Nothing
GetAllTables = tmpTables
End Function
You should then be able to run a query like this
Code:
SELECT GetAllTables() AS TableNames;
Which will return a coma delimited string of all your tables.
You can then use split to put this into an array, iterate through the array and find the tables you need (assuming a standard naming convention of some sort) and build a union query based on them.
Disclaimer: I really don't recommend this as a good solution, just as something that might work with the database structure you have to work with.
|
Hi,
Thanks for the advise! Wow - that's complicated (to a relative newbie like me) but interesting! I'm still trying to get my head around it!
Interesting to see the way the tables are stored, hadn't been aware of that. I shall have a play around and see what happens.
The solution I had been working on was to create a second database in which a list of the table names are stored. I then tried to nest the bit where the recordset is created inside a select statement, so that it would work as follows:
DB1 - The table with all the user information
DB2 - A second table which just contains a table with a list of the names of the tables from DB1
- Create RecordSet based on DB2
- Gets name of table from DB2
- Creates RecordSet from DB1 using the tablename found in DB2 table
- Searches this recordset and outputs any findings
- Loops to top and gets next table name. Recreates the same recordset for DB1, using the next table name from DB2.
I tried to implement this as follows:
IN THE HEAD:
<!--#include file="Connections/imaildata.asp" -->
<!--#include file="Connections/imailinfo.asp" -->
<%
Dim rsTableName
Dim rsTableName_numRows
Set rsTableName = Server.CreateObject("ADODB.Recordset")
rsTableName.ActiveConnection = MM_imailinfo_STRING
rsTableName.Source = "SELECT * FROM tblTableName"
rsTableName.CursorType = 0
rsTableName.CursorLocation = 2
rsTableName.LockType = 1
rsTableName.Open()
rsTableName_numRows = 0
%>
<%
Dim rsData
Dim rsData_numRows
Set rsData = Server.CreateObject("ADODB.Recordset")
rsData.ActiveConnection = MM_imaildata_STRING
rsData.Source = "SELECT * FROM domain1_co_uk"
rsData.CursorType = 0
rsData.CursorLocation = 2
rsData.LockType = 1
rsData.Open()
rsData_numRows = 0
%>
IN THE BODY:
<%
set objTableName = rsTableName("TableName")
while not rsTableName.EOF
objTableName = rsTableName("TableName")
Response.write "Searching table " & "<i>" & objTableName &"</i><br>"
rsData.Source = "SELECT * FROM " & objTableName
rsTableName.MoveNext
Wend
%>
But get the error:
Error Type:
ADODB.Recordset (0x800A0E79)
Operation is not allowed when the object is open.
/imail/TMP8r02a59lyh.asp, line 48
Most of the code is generated by Dreamweaver, and modified by me. I'm a newbie so there are probably a lot of mistakes.....
Any ideas? I tried adding various rsData.close() etc in the tags in the body to no avail...
Anyway, I'm guessing that you can't do this so now I'll try some of the other suggestions!
Cheers,
Stu.