Hi all! This is another exporting access data into excel worksheets but although I'm searching many days now I cannot find a suitable answer to my issue, so here I am hopefully to get your precious assistance.
What I have till now is a code to export a filtered query into a single workbook. What I want to do is to filter about 7 tables based on a value of field "BRANCH" and export the result of each one of them into a separate shett. The final workbook should look like this: sheet1 includes all data of branch 2214 coming from table "CHANGES_FP", sheet2 all data of branch 2214 from table "CHANGES_NS" etc. Have to mention that all tables have different structure and values.
The code I use is :
Set DBS = CurrentDb
Set qdf = DBS.QueryDefs("q_temp")
strSQL = "SELECT DISTINCT BRANCH, BranchDirector, GrTypo FROM tbl_Mtv_SEND;"
Set rstMgr = DBS.OpenRecordset(strSQL, dbOpenDynaset, dbReadOnly)
Do While rstMgr.EOF = False
strMgr = DLookup("BRANCH", "T_BranchList", _
"BRANCH = " & rstMgr!BRANCH.Value)
strSQL = "SELECT * FROM Mtv_SEND WHERE " & _
"BRANCH = " & rstMgr!BRANCH.Value & ";"
qdf.sql = strSQL
qdf.Close
' Replace C:\FolderName\ with actual path
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"q_temp", "D:\DAAP\" & strMgr & "-" & Format(Now(), _
"ddMMMyyyy") & ".xls"
ExcelFile = "D:\DAAP\" & strMgr & "-" & Format(Now(), _
"ddMMMyyyy") & ".xls"
ExcelWorksheet = "q_temp"
Ques = "C:\Users\APC\Desktop\AUDIT PROJECT\DAILY AUDIT DB.accdb"
QueryName = "q_temp"
Can you please help resolve this?
Thank you in advance.
What I have till now is a code to export a filtered query into a single workbook. What I want to do is to filter about 7 tables based on a value of field "BRANCH" and export the result of each one of them into a separate shett. The final workbook should look like this: sheet1 includes all data of branch 2214 coming from table "CHANGES_FP", sheet2 all data of branch 2214 from table "CHANGES_NS" etc. Have to mention that all tables have different structure and values.
The code I use is :
Set DBS = CurrentDb
Set qdf = DBS.QueryDefs("q_temp")
strSQL = "SELECT DISTINCT BRANCH, BranchDirector, GrTypo FROM tbl_Mtv_SEND;"
Set rstMgr = DBS.OpenRecordset(strSQL, dbOpenDynaset, dbReadOnly)
Do While rstMgr.EOF = False
strMgr = DLookup("BRANCH", "T_BranchList", _
"BRANCH = " & rstMgr!BRANCH.Value)
strSQL = "SELECT * FROM Mtv_SEND WHERE " & _
"BRANCH = " & rstMgr!BRANCH.Value & ";"
qdf.sql = strSQL
qdf.Close
' Replace C:\FolderName\ with actual path
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"q_temp", "D:\DAAP\" & strMgr & "-" & Format(Now(), _
"ddMMMyyyy") & ".xls"
ExcelFile = "D:\DAAP\" & strMgr & "-" & Format(Now(), _
"ddMMMyyyy") & ".xls"
ExcelWorksheet = "q_temp"
Ques = "C:\Users\APC\Desktop\AUDIT PROJECT\DAILY AUDIT DB.accdb"
QueryName = "q_temp"
Can you please help resolve this?
Thank you in advance.