Run a Module from an event proceedure

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
 
D

Douglas J Steele

The On Click property for the Command4 command button needs to be set to
[Event Procedure].
 
K

Keith Wilby

nFaux said:
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()

"Call FunctionName()" should work, but the code you've posted is from a
Click event. If you put the code into a module as a function then "Call"
along with the function name and any required arguments should work.

Keith.
www.keithwilby.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top