A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How to Pass a Parm from VBS script to Access 2007



 
 
Thread Tools Display Modes
  #11  
Old April 22nd, 2010, 07:29 PM posted to microsoft.public.access
Steve[_77_]
external usenet poster
 
Posts: 1,017
Default How to Pass a Parm from VBS script to Access 2007

Brad,

One way you can do this is to use Windows Scheduler to open your database
file at a preset time. Then in your database have an autoexec macro that
runs your reports. You could even have a separate database with linked
tables and just your reports. The purpose of this database would be to just
run your off hours reports.

Steve



"Brad" wrote in message
...
Hans,

Thanks for the help and the great examples.

We haven't figured everything out yet, but I believe that we are one step
closer.

We are in the process of automating the running of several reports during
"off hours".

Your assistance will help us put the foundation pieces in place.

Thanks again,

Brad


"Hans Up" wrote:

Brad wrote:
Hans,

Same Sub each time, but the Parameter that we would like to pass from
the
Windows Script to this Sub in Access may have a different value each
time.


OK, the same Sub each time would make it simpler. But while I was
waiting I tried an approach inspired by Tom's suggestion to offer more
flexibility.

You need something which fires when the database starts to accept the
parameter you're feeding with the /cmd switch. In my first try, I used
my form's open event because I already had that set up and I have little
experience with macros.

You could use an autoexec macro, but I chose to create a macro I called
"mcrStartController" and trigger it with the /x command line switch.

The macro consists of a single RunCode line, and the Function Name box
contains Controller()

Essentially all the Controller function does is break the strings out
from the Command() function and feed parameters to the appropriate sub:

Public Function Controller()
Dim varArguments As Variant
Dim i As Integer
Dim strMsg As String
varArguments = Split(Command())

Select Case varArguments(0)
Case "YourSub"
YourSub varArguments(1)
Case "DoubleIt"
DoubleIt varArguments(1)
Case Else
'log this if nobody will be around for the MsgBox
strMsg = "'" & varArguments(0) & "' not usable"
MsgBox strMsg
End Select
End Function

And here are two subs which can be called from Controller:

Public Sub YourSub(ByVal pstrVbsParam)
Dim strMsg As String
strMsg = "Hello " & pstrVbsParam
MsgBox strMsg
End Sub

Public Sub DoubleIt(ByVal pstrNumber As Double)
MsgBox pstrNumber & " * 2 = " & CStr(Val(pstrNumber) * 2)
End Sub

And this is the VBS which starts everything:

Dim objShell
Dim strExe
Dim strDb
Dim strParam
Dim strMacro

Set objShell = WScript.CreateObject("WScript.Shell")
strExe = "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"
strDb = "C:\Access\wip\version_control\vc.mdb"
strMacro = "mcrStartController"

'strParam = "YourSub World"
strParam = "DoubleIt 5.2"
'strParam = "Deliberate failure here"

ObjShell.exec(strExe & " " & strDb & " /x " & strMacro & _
" /cmd " & strParam)
Set ObjShell = Nothing

It seems kind of fiddly, but it works. I couldn't see a simpler route
to get there. In your case, since you're dealing with only one sub, you
can simplify this thing.

I'm curious how you will feed it different parameters each time. Will
you modify the VBS script to change parameters values, or have you
worked out a slick alternative?
.



  #12  
Old April 22nd, 2010, 09:19 PM posted to microsoft.public.access
Hans Up
external usenet poster
 
Posts: 284
Default How to Pass a Parm from VBS script to Access 2007

Brad wrote:
We are in the process of automating the running of several reports during
"off hours".


Hey! That's what I was thinking of trying.

My plan is to store the names of the reports in rows in a job queue
table. The sub fired by the database macro would fetch those names in a
recordset, then loop through the recordset to print out each report.
That approach will avoid the need to feed a parameter to my sub from a
VBS script.
  #13  
Old April 23rd, 2010, 04:13 PM posted to microsoft.public.access
Brad
external usenet poster
 
Posts: 943
Default How to Pass a Parm from VBS script to Access 2007

Steve and Hans,

Thanks for the great ideas. I really appreciate your help.

I like the idea of the Windows Scheduler initiating an Access DB that
contains a table of report names. The info in this table would then control
which reports are run. We are planning to automatically e-mail some reports
and/or store some reports in folders in PDF format.

The one piece that I still don't quite understand is how to use the Access
DB that has the "report" table to link to a second database that has the
table and reports. I understand how a person can link to tables, but I don't
understanding linking to reports that are in a second Database. I must be
missing something.

Thanks,
Brad


"Hans Up" wrote:

Brad wrote:
We are in the process of automating the running of several reports during
"off hours".


Hey! That's what I was thinking of trying.

My plan is to store the names of the reports in rows in a job queue
table. The sub fired by the database macro would fetch those names in a
recordset, then loop through the recordset to print out each report.
That approach will avoid the need to feed a parameter to my sub from a
VBS script.
.

  #14  
Old April 23rd, 2010, 04:39 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default How to Pass a Parm from VBS script to Access 2007

On Fri, 23 Apr 2010 08:13:01 -0700, Brad
wrote:

The one piece that I still don't quite understand is how to use the Access
DB that has the "report" table to link to a second database that has the
table and reports. I understand how a person can link to tables, but I don't
understanding linking to reports that are in a second Database. I must be
missing something.


I'd certainly suggest using a split database (tables in a shared backend,
forms, reports, queries and code in a frontend on each user's desk), quite
independent of this automation issue. See
http://www.granite.ab.ca/access/splitapp.htm or
http://allenbrowne.com/ser-01.html for details.

However, it's probably not necessary to have the report table in a separate
database from the reports themselves. You could either use a separate,
dedicated frontend just for the batch job, or even include the table of
reports and the code in your general-purpose frontend, and have it activated
with a command line switch from the Scheduler, as suggested earlier in this
thread.
--

John W. Vinson [MVP]
  #15  
Old April 23rd, 2010, 07:15 PM posted to microsoft.public.access
Steve[_77_]
external usenet poster
 
Posts: 1,017
Default How to Pass a Parm from VBS script to Access 2007

Hi Brad,

You don't need a table of report names! Just put a copy of the reports you
want to run off hours in your off hours database. Put any queries you use
for record sources for the reports in the off hours database. Link to all
tables you use in the queries and/or in the reports. Then all you need is
code to run all the reports in the off hours database.

Steve


"Brad" wrote in message
news
Steve and Hans,

Thanks for the great ideas. I really appreciate your help.

I like the idea of the Windows Scheduler initiating an Access DB that
contains a table of report names. The info in this table would then
control
which reports are run. We are planning to automatically e-mail some
reports
and/or store some reports in folders in PDF format.

The one piece that I still don't quite understand is how to use the Access
DB that has the "report" table to link to a second database that has the
table and reports. I understand how a person can link to tables, but I
don't
understanding linking to reports that are in a second Database. I must be
missing something.

Thanks,
Brad


"Hans Up" wrote:

Brad wrote:
We are in the process of automating the running of several reports
during
"off hours".


Hey! That's what I was thinking of trying.

My plan is to store the names of the reports in rows in a job queue
table. The sub fired by the database macro would fetch those names in a
recordset, then loop through the recordset to print out each report.
That approach will avoid the need to feed a parameter to my sub from a
VBS script.
.



  #16  
Old April 23rd, 2010, 07:26 PM posted to microsoft.public.access
Hans Up
external usenet poster
 
Posts: 284
Default How to Pass a Parm from VBS script to Access 2007

Brad wrote:
Steve and Hans,

Thanks for the great ideas. I really appreciate your help.

I like the idea of the Windows Scheduler initiating an Access DB that
contains a table of report names. The info in this table would then control
which reports are run. We are planning to automatically e-mail some reports
and/or store some reports in folders in PDF format.


You can use an autoexec macro, as suggested elsewhere, to kick off your
operation. Just remember if anyone opens the database without holding
down the shift key, the reports will start spitting out. That is the
reason I suggested using a separate macro and including its name after
the /x switch.

Sounds like your version of a "WhichReports" table might benefit from an
additional field for output destination: email; PDF; paper. Or maybe
put the output destinations in a related table if one report may ever
have more than one destination. I was thinking about something simpler
.... just a field for report name, and a Yes/No field to indicate whether
that report should be included in the next scheduled print cycle.

The one piece that I still don't quite understand is how to use the Access
DB that has the "report" table to link to a second database that has the
table and reports. I understand how a person can link to tables, but I don't
understanding linking to reports that are in a second Database. I must be
missing something.


The way I imagined it is the db started by Windows Scheduler contains
both the WhichReports table and the actual report objects. If you
absolutely need them in separate databases, consider linking
WhichReports into the database which contains the reports and have the
scheduler start the database which contains the reports.

Regards,
Hans
  #17  
Old April 23rd, 2010, 07:59 PM posted to microsoft.public.access
Brad
external usenet poster
 
Posts: 943
Default How to Pass a Parm from VBS script to Access 2007

Steve,

Thanks!

Brad


"Steve" wrote:

Hi Brad,

You don't need a table of report names! Just put a copy of the reports you
want to run off hours in your off hours database. Put any queries you use
for record sources for the reports in the off hours database. Link to all
tables you use in the queries and/or in the reports. Then all you need is
code to run all the reports in the off hours database.

Steve


"Brad" wrote in message
news
Steve and Hans,

Thanks for the great ideas. I really appreciate your help.

I like the idea of the Windows Scheduler initiating an Access DB that
contains a table of report names. The info in this table would then
control
which reports are run. We are planning to automatically e-mail some
reports
and/or store some reports in folders in PDF format.

The one piece that I still don't quite understand is how to use the Access
DB that has the "report" table to link to a second database that has the
table and reports. I understand how a person can link to tables, but I
don't
understanding linking to reports that are in a second Database. I must be
missing something.

Thanks,
Brad


"Hans Up" wrote:

Brad wrote:
We are in the process of automating the running of several reports
during
"off hours".

Hey! That's what I was thinking of trying.

My plan is to store the names of the reports in rows in a job queue
table. The sub fired by the database macro would fetch those names in a
recordset, then loop through the recordset to print out each report.
That approach will avoid the need to feed a parameter to my sub from a
VBS script.
.



.

  #18  
Old April 24th, 2010, 11:43 AM posted to microsoft.public.access
david
external usenet poster
 
Posts: 34
Default How to Pass a Parm from VBS script to Access 2007


Rem Create a app object:

set app=createobject("access.application")

app.opencurrentdatabase(strdb)

Rem Run function with parameters:

app.run(myPublicFunction,1,"a")


(david)





"Brad" wrote in message
...
We have a VBS Script that initiates a Sub in an Access 2007 DB.

This works nicely.

We now would like to pass a parm from our VBS script to this Sub. It is
our
understanding that the "command" field in our VBA code will contain the
passed data.

What we can't figure out is how to code the VBS script to pass the parm to
Access.

An example would be most appreciated.

Thanks,

Brad



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:13 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.