Hello All and happy New Year
I started a thread a while ago - thread700-1762245 -
In this I was trying to find out how to loop through hundreds of tables and extract data to a single table.
With help from those here I was able to do this.
I now need to take this project further and would appreciate help over the next few weeks developing the code robustly,
The concept is as follows:
I need to develop one table on which I can run Reports.
The database that I am using is commercially written, so I cannot alter the way in which it is structured.
It is a property database.
Each property is assigned its own table (I know this is not normalised - but it is, what it is)
The tables are identical in structure and are numbered 1,2,3 etc... these numbers correspond to the REFERENCE in the PROPERTY table.
I have created a table to hold the extracted data and called it TEST
The code which I have so far (and is working) is below (Thank you Mr Hookom)
So to get to my goal I need to develop the code to meet the following:
1. Rather than extract 1 record from each table I need to extract ALL records BETWEEN a specified date range.
(On my form I have a textboxes called DateStart and DateEnd)
2. I need the code only to look at tables which match the exact reference from the PROPERTY table.
(i.e. for Property 1, in the PROPERTY table there will be a number 1 in the REFERENCE field.
In the database there will be a table called 1, but there will also be a table called DT1 - I'm not sure if the current code ignores the DT1 or looks at both of these)
3. If a table is missing, I need the code to pop up a warning showing the missing table number. Once the warning is acknowledge the code will skip it and continue)
4. Also if possible, I would like to add a field to the TEST table called Property_Link, to which
I would like to add the number of the table being processed so I can tell which property the records came from.
I hope the above may interest someone. Help much appreciated.
My VBA is rather poor and I really need this code to be robust, accurate and reliable.
Many thanks in anticpation of your assistance.
Regards Mark
I started a thread a while ago - thread700-1762245 -
In this I was trying to find out how to loop through hundreds of tables and extract data to a single table.
With help from those here I was able to do this.
I now need to take this project further and would appreciate help over the next few weeks developing the code robustly,
The concept is as follows:
I need to develop one table on which I can run Reports.
The database that I am using is commercially written, so I cannot alter the way in which it is structured.
It is a property database.
Each property is assigned its own table (I know this is not normalised - but it is, what it is)
The tables are identical in structure and are numbered 1,2,3 etc... these numbers correspond to the REFERENCE in the PROPERTY table.
I have created a table to hold the extracted data and called it TEST
The code which I have so far (and is working) is below (Thank you Mr Hookom)
Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strSQLInsert As String
Set db = CurrentDb
'strSQL = "SELECT [Reference] FROM Property WHERE [Archive]=True ORDER BY [Reference]"
strSQL = "SELECT [Reference] FROM Property ORDER BY [Reference]"
Set rs = db.OpenRecordset(strSQL)
Do While Not rs.EOF
strSQLInsert = "Insert Into TEST" & _
" Select TOP 1 * From [" & rs("Reference") & "] Order By Reference Desc "
db.Execute strSQLInsert, dbFailOnError
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
MsgBox "Complete"
So to get to my goal I need to develop the code to meet the following:
1. Rather than extract 1 record from each table I need to extract ALL records BETWEEN a specified date range.
(On my form I have a textboxes called DateStart and DateEnd)
2. I need the code only to look at tables which match the exact reference from the PROPERTY table.
(i.e. for Property 1, in the PROPERTY table there will be a number 1 in the REFERENCE field.
In the database there will be a table called 1, but there will also be a table called DT1 - I'm not sure if the current code ignores the DT1 or looks at both of these)
3. If a table is missing, I need the code to pop up a warning showing the missing table number. Once the warning is acknowledge the code will skip it and continue)
4. Also if possible, I would like to add a field to the TEST table called Property_Link, to which
I would like to add the number of the table being processed so I can tell which property the records came from.
I hope the above may interest someone. Help much appreciated.
My VBA is rather poor and I really need this code to be robust, accurate and reliable.
Many thanks in anticpation of your assistance.
Regards Mark