G
Guest
I have a module set up to export a query to excel and parse the data into
various tabs. Works great, when go into the module to run it. I want to run
that module from an event procedure from a form. (on click from a button)
I see that some have refered to a "Call" option, but have not been sucessful
in getting the module to run. VB for module is below:
Option Compare Database
Public Initiative As String
Private Sub Command4_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim vWorkbook As String
vWorkbook = "C:\file.xls"
Set db = CurrentDb
Set rst = db.OpenRecordset("TableName")
Do Until rst.EOF
Initiative = rst.Fields("Initiative") 'This is the primary for this
Table
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"QueryName", vWorkbook, , Initiative
'Record is the foreign for the main table in QueryName
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
MsgBox "All Done", vbInformation, "Data Transfer"
End Sub
Public Function Selected_Center()
Selected_Center = Initiative
End Function
various tabs. Works great, when go into the module to run it. I want to run
that module from an event procedure from a form. (on click from a button)
I see that some have refered to a "Call" option, but have not been sucessful
in getting the module to run. VB for module is below:
Option Compare Database
Public Initiative As String
Private Sub Command4_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim vWorkbook As String
vWorkbook = "C:\file.xls"
Set db = CurrentDb
Set rst = db.OpenRecordset("TableName")
Do Until rst.EOF
Initiative = rst.Fields("Initiative") 'This is the primary for this
Table
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"QueryName", vWorkbook, , Initiative
'Record is the foreign for the main table in QueryName
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
MsgBox "All Done", vbInformation, "Data Transfer"
End Sub
Public Function Selected_Center()
Selected_Center = Initiative
End Function