How to Run Scripts and Open Other Applications from MS Access Using VBA
ฝัง
- เผยแพร่เมื่อ 5 ก.ย. 2024
- In this episode, we're going to explore one way that we can use our MS Access app to start other applications and scripts, like our Python scripts that can give us all kinds of goodies. Once Access applications become more mature, they usually have some requirement to open other applications or files on the user's computer, to assist the user in their tasks. WScript.Shell allows us to use the Windows Script Host to open these resources for the user. Let's go and open some scripts from Access!
Join me on Patreon!
/ mackenziedataengineering
Want the code from this video?
mackenziemacken...
Interested in transforming your career or finding your next gig?
system.billzon...
Want my team to do a project for you? Let's get to it!
system.billzon...
Contact form you can find at www.mackenziema...
Follow me on social media:
/ mackenziedataanalytics
/ seamacke
/ seamacke
/ seamacke
/ psmackenzie
Get Microsoft Office including Access:
click.linksyne...
Got a TH-cam Channel? I use TubeBuddy, it is awesome. Give it a try:
www.tubebuddy....
#msaccess #vba #python
This channel has all sorts of golden nuggets! I was just asking myself this question the other day.
Eventually we all run into that situation where we need to run something outside of Access!
Hi . l have run error (method run of object 'Iwshshell3'failed
Can you post your code?
Hi Sean, thanks for the video. Question, I have two scripts to run, how would I write the code for that?
In your button code, you can just make two lines with RunFromShell in it. One for each script you need to run. Note that tasks in those may execute asynchronously. The second may not wait for the first to finish before starting the second. I believe there is a switch to make it wait, or you can try other methods.
Hi SM
Is it possible to run “saved Export” from vb script please (then able to use task scheduler)
You can run vbs files from the Task Scheduler, but I have found it *much* better to always run your vbs in a bat or cmd file, then schedule the bat or cmd file in the scheduler. Basically, make a mybatch.txt file with one line, C:\mypath\myscript.vbs, then rename the txt file to mybatch.cmd (the icon will change). The schedule mybatch.cmd in your Scheduler. This adds to the stability of running vbs under the scheduler.
Sorry, but work path not correct! *.bat file placed in wscript_shell folder but when run show folder "...\Documents"! How can runed *.dat file from wscript_shell folder?
You can try changing the path to "myfile.bat", or "~\myfile.bat" to run from the same folder. Or ".\myfile.bat". Let me know how it goes!
@@seanmackenziedataengineering doesn't work because wrong paths! For example. The MS Access file is located in c:\Users\sean\Documents. The Batch file is located in c:\dev\wscript_shell. If you run the batch file without MS Access (from windows folder) we will see in the batch window c:\dev\wscript_shell>........ When run the batch file from MS Access we will see in the batch window c:\Users\sean\Documents>..... How to make it so that when run the batch file from MS Access, we see in the batch window c:\dev\wscript_shell - the folder where the batch file is located?
@@andriyos_ Ah ok. You can add one line to batch file, at the very start:
cd C:\dev\wscript_shell
Then it will run everything from that directory and show it in the command line.
As always, you over-delivered Sean! Excellent video. Thanks for the solution. Very powerful stuff.
Much appreciated, thanks for the feedback!
Hi Guru
I use Task schedular to run VBS back up on handful of specific users
Down side of it is user need to log on the day/ time for it to happen.
Q = How can I use environ(“”username”) and use select statement to run the VBS file
On Form “On load “ event using Case Statement please? ( limiting on selected users)
Or any other way more effective🤔
The nice thing of using VBS is that you can configure it to run anytime, and you really don't need to have any user open Access or anything like that. It sounds like you are not backing up files, but instead are selecting data from your Access db. When you use Windows Task Scheduler, there is a way you can specify for the script to "run whether user is logged on or not". You will choose the account that will execute the script. So, why not use an admin or service login? You can securely store credentials with the task. Then, by using one account, you can run the same task for all users. There are a couple of gotchas, but I can explain more with screenshots if you want to email me.
❤ thanks
Admin rights is the issue
thanks
Thanks for checking it out!
Handy tool📎
Like the way handle the vbs file
Is there a way to compress or hide the script from the user please?
Yes, you can hide the batch file window by using a zero as a second argument:
objShell. Run strFile, 0
or, set back to visible run:
objShell. Run strFile, 1
Give it a go
Nice tip 📎🗳
Hi Sean
How to run a query from vbscript please ( for automation purposes) using task scheduler
Hi Sean. Yet another useful video, as always - Thank you. I have tried using this exact technique, however for some reason, it won't run files that are located on my root drive, or in other app folders such as Program Files. It works perfectly fine when the files are located on the desktop or in Documents. Do you know of a way to fix this issue? Thanks
This is almost always due to permissions issues. Either Access does not have permission to access those locations. Are you running O365?
@@seanmackenziedataengineering Hello again. Thanks for your response. I actually resolved the issue. I had forgotten to use the double-double quotes in the file path for the Shell.Run function 🤣
@@seanmackenziedataengineering I actually used your vbScript Deploy template to make an automatic updater for an Access front-end I made for the company I work for. I modified your script so that it now works as a launcher for the front-end itself. Basically, if file doesn't exist or is not up-to-date, then copy file from network to deploy folder. Then run it with the Shell.Run function. So basically when the front-end user opens the shortcut on their desktop, it will run the vbScript, which then launches the Access file. What is your opinion on this technique? It works fine on my own computer, but I'm worried that other people might run into permission issues
@@simonmaersk Ah ok! That will do it. Glad it worked for you!
@@simonmaersk If it works, perhaps test it and see how it does with end-users.