There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Business Applications
Tag Cloud
audio backup blue screen boot bsod compaq computer cpu crash dell drivers dvd error excel firefox format freeze freezing hard drive install internet internet explorer kb951748 laptop loss of internet malware memory motherboard network networking outlook outlook 2007 problem restart screen slow sound spyware startup trojan update virus vista website windows windows xp winxp wireless zonealarm zone alarm
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Access 2003 & Batch File


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
computerman29642's Avatar
Computer Specs
Senior Member with 1,669 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
09-Jul-2008, 02:56 PM #1
Question Solved: Access 2003 & Batch File
Does anyone know if it is possible to run a batch file when Access 2003 database is opened? If so, how would that be done?
computerman29642's Avatar
Computer Specs
Senior Member with 1,669 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
09-Jul-2008, 03:17 PM #2
Let me know if having an example of the batch file would help.
Rollin_Again's Avatar
Distinguished Member with 2,906 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
09-Jul-2008, 03:43 PM #3
Open Access and press ALT + F11 to open the VB editor. Click INSERT >> MODULE and paste the code below into the blank code module. Just change the path of the batch file. Then create a new macro in Access by clicking on the macro link and then pressing the New button. The macro builder should now open and you will create the Access macro. At the top of the macro builder select RunCode as your action. At the bottom of the macro builder will be a text field for you to enter your function name. This is where you will put the name of the function you previously created called CallBatch (). When you click the SAVE button you will be prompted to name your macro. Just name it AutoExec and it will fire automatically when the database is opened.

Code:
Public Function CallBatch()
Shell "C:\MyBat.bat"
End Function
Regards,
Rollin
__________________
Protect your computer and keep it free of pests and other spyware. Download AdAware, Spybot, ZoneAlarm and lots of other great utilities at PC World / SnapFiles / Major Geeks, Tech Guy Stuff

Help Keep this site free by making a small donation

http://www.techguy.org/donate.html

tsghelp at live dot com / support

Last edited by Rollin_Again : 09-Jul-2008 03:49 PM.
Rollin_Again's Avatar
Distinguished Member with 2,906 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
09-Jul-2008, 04:12 PM #4
What exactly does the batch file do? You can probably just bypass the batch file and do everything using VB script.

Regards,
Rollin
computerman29642's Avatar
Computer Specs
Senior Member with 1,669 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
09-Jul-2008, 04:13 PM #5
The first thing the batch file does is makes a copy of the database for backup. Then the batch file compacts and repairs the database.

The batch file is failing on the compact and repair part. I get an error message stating the database is already opened.

Last edited by computerman29642 : 09-Jul-2008 04:25 PM.
Rollin_Again's Avatar
Distinguished Member with 2,906 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
09-Jul-2008, 04:30 PM #6
Here is a link with sample code to copy and compact a database using VBA.

http://forums.devarticles.com/micros...vba-24958.html

Feel free to post your code from your batch file.

Regards,
Rollin
computerman29642's Avatar
Computer Specs
Senior Member with 1,669 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
09-Jul-2008, 04:37 PM #7
Here is the code I have in my batch file...

Code:
@echo off

REM Creates a copy of the MDB file, and places the file in the Backup Directory

XCOPY "C:\Movie\Movie.mdb" "C:\Movie\Backup" /D /y

REM Compacts and Repairs the DB

"C:\ProgramFiles\MicrosoftOffice\Office\msaccess.exe" "C:\Movie\Movie.mdb" /compact /repair
Mine seems a little bit simpler than the code found in the link you provided. Maybe that is why mine does not work....LOL!

Last edited by computerman29642 : 09-Jul-2008 05:44 PM.
computerman29642's Avatar
Computer Specs
Senior Member with 1,669 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
10-Jul-2008, 03:38 PM #8
I tried using portions of the code in the link provided, but I cannot seem to get the code to work.

Any thoughts?
Rollin_Again's Avatar
Distinguished Member with 2,906 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
10-Jul-2008, 03:47 PM #9
Quote:
Originally Posted by gamecockfan View Post
I tried using portions of the code in the link provided, but I cannot seem to get the code to work.

Any thoughts?
Are you getting an error? What is happening?

Regards,
Rollin
computerman29642's Avatar
Computer Specs
Senior Member with 1,669 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
10-Jul-2008, 04:08 PM #10
I want the code to run when I open the database, so I placed the code behind a function. I named the Macro "AutoExec". Nothing happens. The database does not compact & repair, and no backup is created.
Rollin_Again's Avatar
Distinguished Member with 2,906 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
10-Jul-2008, 05:03 PM #11
Replace all your VBA code with a simple message box to see if the code is even being fired by the AutoExec macro.

You do have the AutoExec macro set to call the function you created right? When you are building the macro in Access you should be able to click the three little dots next to the function name text field and drill through and pick the function.

NOTE: If you are manually typing the function name to fire in the macro builder you need to include the parentheses after the function name.

Regards,
Rollin
__________________
Protect your computer and keep it free of pests and other spyware. Download AdAware, Spybot, ZoneAlarm and lots of other great utilities at PC World / SnapFiles / Major Geeks, Tech Guy Stuff

Help Keep this site free by making a small donation

http://www.techguy.org/donate.html

tsghelp at live dot com / support

Last edited by Rollin_Again : 10-Jul-2008 05:16 PM.
computerman29642's Avatar
Computer Specs
Senior Member with 1,669 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
10-Jul-2008, 05:48 PM #12
The messge box worked. I guess I screwed up the code some how.
Rollin_Again's Avatar
Distinguished Member with 2,906 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
10-Jul-2008, 05:50 PM #13
Post your code please.

Regards,
Rollin
computerman29642's Avatar
Computer Specs
Senior Member with 1,669 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
10-Jul-2008, 05:50 PM #14
Here is the modified code...

Code:
Option Compare Database
Option Explicit

Public Function Test()
Dim dbPath As String, OldDbName As String, NewDbName As String, DbBackup As String
Dim Response As Integer, fs As Object
dbPath = Application.CurrentProject.Path
OldDbName = "ReorderMonitoring" & ".mdb"
NewDbName = "ReorderMonitoringNew" & ".mdb"
DbBackup = Mid(OldDbName, 1, Len(OldDbName) - 4) & "_" & Format(Date, "mmddyy") & ".mdb"
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFile dbPath & "\" & OldDbName, dbPath & "\" & DbBackup
Set fs = Nothing
MsgBox "Did this work"
End Function
I get some kind of popup box letting me know the action failed. The only option I have is to press the Halt command button on the popup box.
computerman29642's Avatar
Computer Specs
Senior Member with 1,669 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
10-Jul-2008, 05:56 PM #15
I believe it is having an issue with this line.

Code:
fs.CopyFile dbPath & "\" & OldDbName, dbPath & "\" & DbBackup
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 05:14 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.