How to run it from command line?

Jeff06

Registered User.
Local time
Today, 16:07
Joined
Jan 9, 2007
Messages
26
I have a vba module call runme with this code
Code:
Option Compare Database
Sub makequery()
Dim db As DAO.Database
Dim qry As DAO.QueryDef
Dim rs As DAO.Recordset
Dim fld As DAO.Field


Dim XlApp As Excel.Application
Dim xlwb As Excel.Workbook
Dim xlws As Excel.worksheet
Dim xlrn As Excel.Range

Dim x As Integer


Set db = Access.CurrentDb
Set qry = db.QueryDefs("q1")
Set rs = qry.OpenRecordset

Set XlApp = New Excel.Application
XlApp.Visible = True
Set xlwb = XlApp.Workbooks.Add
Set xlws = xlwb.ActiveSheet

x = 1
For Each fld In rs.Fields
xlws.Cells(1, x).Value = fld.Name
x = x + 1
Next fld

Set xlrng = xlws.Cells(2, 1)
xlrng.CopyFromRecordset rs
xlws.Columns.AutoFit
rs.Close
qry.Close



qry.Close


End Sub

I can run it from vb eidit interface by hitting run.
How can I run it from command line?

I tried "msaccess.exe" "C:\Documents and Settings\jzhu\My Documents\test.mdb" /Excl /X "runme"
But it does not seems to work.

THX.
Jeff
 
Jeff,

Put the code in a Public module.

Have your Autoexec Macro run the code.

Wayne
 
Thank you very much.
Would you please give me more instruction on how to "Have your Autoexec Macro run the code"?
Thanks.
JEFF
 
Again
how to "Have your Autoexec Macro run the code"
Can someone help.
Thanks
 
Jeff,

Make a new macro - AutoExec

Action = RunCode
FunctionName = YourFunction()

Then, just put your function in a Public Module and it will execute when
the database opens.

Wayne
 

Users who are viewing this thread

Back
Top Bottom