Hello,
I am trying to export a table in access based on a unique field called Group_Name. Say my table has 100 records. 10 of those records belong to Group1, 10 belong to Group 2, and so on. What I want to do is export those groups individually to an excel file and have that file named somting like Group1_Premium Detail Report.
Here is the Code I have so far. I have a feeling I am close. When I run the code it does not seem to like strrsql2 :banghead:
Dim strsql As String
Dim strsql2 As String
Dim strfilename As String
Dim strpath As String
strpath = "C:\Users\Desktop\Home\"
strsql = "select distinct Group_name From Tbl_GrpName"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strsql)
rs.MoveLast
rs.MoveFirst
Do Until rs.EOF
strsql2 = "Select Tbl_DetailRpt.* " _
& "from Tbl_DetailRpt " _
& "where [Tbl_DetailRpt].[Group_Name]=" & rs!Group_name
strfilename = [rs]![Group_name] & " Premium Detail Report"
DoCmd.OutputTo acOutputQuery, strsql2, , strpath & "REC01" & "_" & strfilename & ".xls", True, ""
DoCmd.TransferSpreadsheet acExport, , strsql2, strfilename, True
rs.MoveNext
strfilename = ""
strsql2 = ""
Loop
Exit Sub
End Sub
Thanks in advance for the input.
I am trying to export a table in access based on a unique field called Group_Name. Say my table has 100 records. 10 of those records belong to Group1, 10 belong to Group 2, and so on. What I want to do is export those groups individually to an excel file and have that file named somting like Group1_Premium Detail Report.
Here is the Code I have so far. I have a feeling I am close. When I run the code it does not seem to like strrsql2 :banghead:
Dim strsql As String
Dim strsql2 As String
Dim strfilename As String
Dim strpath As String
strpath = "C:\Users\Desktop\Home\"
strsql = "select distinct Group_name From Tbl_GrpName"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strsql)
rs.MoveLast
rs.MoveFirst
Do Until rs.EOF
strsql2 = "Select Tbl_DetailRpt.* " _
& "from Tbl_DetailRpt " _
& "where [Tbl_DetailRpt].[Group_Name]=" & rs!Group_name
strfilename = [rs]![Group_name] & " Premium Detail Report"
DoCmd.OutputTo acOutputQuery, strsql2, , strpath & "REC01" & "_" & strfilename & ".xls", True, ""
DoCmd.TransferSpreadsheet acExport, , strsql2, strfilename, True
rs.MoveNext
strfilename = ""
strsql2 = ""
Loop
Exit Sub
End Sub
Thanks in advance for the input.