Hi all
Again, I've searched for ages but I think there's a particular element of what I'm trying to do that I can't find the answer to. The code below basically loops through the table (tblMaster) and creates a new table for each Agency. All works fine.
What I've now been asked to do is add a second element - so that the code will create a separate table for each Agency for each Customer. I just can't work out how to adapt this code to add in this requirement. Customer is another field in the tblMaster. Any help with this would be greatly appreciated.
Again, I've searched for ages but I think there's a particular element of what I'm trying to do that I can't find the answer to. The code below basically loops through the table (tblMaster) and creates a new table for each Agency. All works fine.
What I've now been asked to do is add a second element - so that the code will create a separate table for each Agency for each Customer. I just can't work out how to adapt this code to add in this requirement. Customer is another field in the tblMaster. Any help with this would be greatly appreciated.
Code:
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("select distinct Agency from qryAgency")
While Not rs.EOF
On Error Resume Next
CurrentDb.Execute "DROP TABLE [" & rs("Agency") & "]"
CurrentDb.Execute "SELECT tblMaster.* INTO [" & rs("Agency") & "] FROM tblMaster WHERE Agency=""" & rs("Agency") & """;"
On Error GoTo 0
rs.MoveNext
Wend
rs.Close
Set rs = Nothing