I'm really struggling with this - and have been for about 4 days !!
I have a query called SuppList that contains two fields - supplier and Suppname and has 101 records
I need to loop through this query and use the supplier in each record as the criteria in another query and then output this second query to Excel.
I've got most of it but I'm struggling with the loop part.
Please can anyone help ???
Here is the code so far : (PS - I had this all sorted, but lost my HDD in December - and you guessed it - no back up - serves me right I know )
------------------------------------------------------------------
Function dataex3()
On Error GoTo testExport_Err
Dim strDate As String
Dim strFileName As String
Dim strFilePath As String
Dim strSupp As String
Dim intsupp As Integer
Dim intcnt As Integer
Dim Supplier As Variant
Dim Supplist As DAO.Recordset
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SuppList")
Supplier = rs.Fields("Supplier")
intcnt = 0
intsupp = DCount("[SuppList]![Supplier]", "[SuppList]")
strDate = CStr(DatePart("yyyy", Date) & "_" & (DatePart("m", (Date - 1))))
strFileName = strSupp & strDate & ".xls"
strFilePath = "O:\transferord\test\" & strFileName
For intcnt = 1 To intsupp
DoCmd.OpenQuery "SuppList", acNormal, acReadOnly
Set rs = db.OpenRecordset("SuppList")
For Each Supplier In Supplist
strSupp = Supplier
DoCmd.OpenQuery "CodeInvData", acNormal, acReadOnly
DoCmd.TransferSpreadsheet acExport, 8, "CodeInvData", strFilePath, True, ""
Next Supplier
Next
----------------------------------------------------------
THanks
I have a query called SuppList that contains two fields - supplier and Suppname and has 101 records
I need to loop through this query and use the supplier in each record as the criteria in another query and then output this second query to Excel.
I've got most of it but I'm struggling with the loop part.
Please can anyone help ???
Here is the code so far : (PS - I had this all sorted, but lost my HDD in December - and you guessed it - no back up - serves me right I know )
------------------------------------------------------------------
Function dataex3()
On Error GoTo testExport_Err
Dim strDate As String
Dim strFileName As String
Dim strFilePath As String
Dim strSupp As String
Dim intsupp As Integer
Dim intcnt As Integer
Dim Supplier As Variant
Dim Supplist As DAO.Recordset
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SuppList")
Supplier = rs.Fields("Supplier")
intcnt = 0
intsupp = DCount("[SuppList]![Supplier]", "[SuppList]")
strDate = CStr(DatePart("yyyy", Date) & "_" & (DatePart("m", (Date - 1))))
strFileName = strSupp & strDate & ".xls"
strFilePath = "O:\transferord\test\" & strFileName
For intcnt = 1 To intsupp
DoCmd.OpenQuery "SuppList", acNormal, acReadOnly
Set rs = db.OpenRecordset("SuppList")
For Each Supplier In Supplist
strSupp = Supplier
DoCmd.OpenQuery "CodeInvData", acNormal, acReadOnly
DoCmd.TransferSpreadsheet acExport, 8, "CodeInvData", strFilePath, True, ""
Next Supplier
Next
----------------------------------------------------------
THanks