Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute Access macro from VBScript 1

Status
Not open for further replies.

Chipper23

IS-IT--Management
Jun 22, 2002
6
0
0
US
I have an Access 2002 database. I am using several tables, macros, and data access pages. I have a data access page that contains a command button, when this button is clicked I need to execute a macro that I have setup that uses the SendObject function to send an Access report to an email address..that's it. I know how to convert my macro to Visual Basic for Applications code, which converts the macro to a statement using DoCmd.SendObject, but this doesn't seem to work in VBScript, which is used in my data access page. How do I execute a macro from within my VBScript code, or What is the proper code for using the SendObject function with VBScript. Thanks so much in advance for any help you provide.
 
You'll need to automate Access. To execute the macro use something like,

Set oAccess = CreateObject("Access.Application")
oAccess.OpenCurrentDatabase "C:\mydb.mdb"
oAccess.DoCmd.RunMacro "MyMacro"
oAccess.CloseCurrentDatabase
oAccess.Quit
Set oAccess = Nothing

To execute the SendObject action use something like,

Set oAccess = CreateObject("Access.Application")
oAccess.OpenCurrentDatabase "C:\mydb.mdb"
oAccess.DoCmd.SendObject 0,"MyTable","HTML (*.html)","To Recipient","CC Recipient","BCC Recipient","My Subject","My Message",True,""
oAccess.CloseCurrentDatabase
oAccess.Quit
Set oAccess = Nothing

Use False above if you want the email to be submitted immediately. Jon Hawkins
 
Works great! I thank you so much for this info. Somewhere along the way I was under the impression that the DoCmd object would not work with VBScript....Thanks so much...
 
I have a similar problem running Data Access Page. My problem is a little bit different.

I have a macros that will call a Print Preview of the Report. The VBA codes are like this one:

********************************************

Private Sub Preview_Report_Click()
On Error GoTo Err_Preview_Report_Click

Dim stDocName As String

stDocName = "Rpt_Samples"
DoCmd.OpenReport stDocName, acPreview

Exit_Preview_Report_Click:
Exit Sub

Err_Preview_Report_Click:
MsgBox Err.Description
Resume Exit_Preview_Report_Click

End Sub
********************************************************

Can anyone help me how to convert this sub procedure into Javascripts or the language that can be used in Data Access Page. So, I can execute the button command from Data Access Page? What I am looking is just a Print Preview of the Report. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top