email a form from VBS file

  • Thread starter Thread starter RT
  • Start date Start date
R

RT

i need to automatically send/email an access report on
every friday.

I tried using sendobject function in a vbs file
*****************************************************
Set objAccess = CreateObject("Access.Application")
objAccess.Visible = True
objAccess.OpenCurrentDatabase "c:\ritu\customer.mdb"
objAccess.doCmd.OpenForm "customer details", acFormDS, , ,
acFormReadOnly, acWindowNormal
'sending the report by email
objAccess.doCmd.SendObject acSendReport, "rpt_customer",
acFormatXLS, "<email add>", , , , , False
********************************************************
when i run the file,it opens access,opens the form,
- asks for file format!!..even though i have mentioned xls
format..
- and after selecting the format..it gives the foll error:

microsoft jet database engine could not find the
object 'rpt_customer'. make sure the object exists and
that you spell the name and the path name correctly "

the same code on click of a button in a form works fine.

is there anything wrong that i am doing? is there any
other method i should be using?
 
RT said:
i need to automatically send/email an access report on
every friday.

I tried using sendobject function in a vbs file
*****************************************************
Set objAccess = CreateObject("Access.Application")
objAccess.Visible = True
objAccess.OpenCurrentDatabase "c:\ritu\customer.mdb"
objAccess.doCmd.OpenForm "customer details", acFormDS, , ,
acFormReadOnly, acWindowNormal
'sending the report by email
objAccess.doCmd.SendObject acSendReport, "rpt_customer",
acFormatXLS, "<email add>", , , , , False
********************************************************
when i run the file,it opens access,opens the form,
- asks for file format!!..even though i have mentioned xls
format..
- and after selecting the format..it gives the foll error:

microsoft jet database engine could not find the
object 'rpt_customer'. make sure the object exists and
that you spell the name and the path name correctly "

the same code on click of a button in a form works fine.

is there anything wrong that i am doing? is there any
other method i should be using?

Some of the constants you're using are defined by Access and aren't
known in your VBScript file, so you have to replace them with the
literal values, like this (watch for line wrap):

'---------------------
Dim objAccess

Set objAccess = CreateObject("Access.Application")

objAccess.Visible = True

objAccess.OpenCurrentDatabase "c:\ritu\customer.mdb"

objAccess.DoCmd.OpenForm "customer details", acFormDS, , ,
acFormReadOnly, acWindowNormal

'sending the report by email
objAccess.DoCmd.SendObject 3, "rpt_customer", "Microsoft Excel (*.xls)",
"<email add>", , , , , False
'---------------------

I must admit, though, that sending in Excel format didn't work on my
system, even though Excel is installed. This code did work for sending
in text and HTML formats, though, so maybe there's something broken on
my system. With luck, it will work on your system.
 
If you still want to use the symbolic constant acFormatXLS, you need to
include the Access Object Library in your References and try:

objAccess.doCmd.SendObject acSendReport, "rpt_customer", _
Access.Constants.acFormatXLS, "<email add>", , , , , False
 
Back
Top