Solved

Opening Access via command line

Posted on 2011-02-25
6
340 Views
Last Modified: 2012-05-11
Guys/Gals,

I want to use the command line to open an Access database, if it isn't opened with the command line, I want it to close immediately, is this possible?

I am fairly sure that I did this back in the days when I was a developer, but that was many years ago now and I have forgotten!

Thanks
Dave
0
Comment
Question by:Runrigger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:karim_hashish
ID: 34978305
Hello Runrigger

I would recommend to use windows powershell and it's very easy according to your experience as a developer before so you will be able to customize the below code easily to meet your needs exactly.

You can download windows powershell from microsoft official website link below if you don't have it.

http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx

For further inquiries or assistance don't hesitate to refer back

Best Regards,

Karim
$adOpenStatic = 3
$adLockOptimistic = 3

$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset

$objConnection.Open("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = c:\scripts\sample.mdb")
$objRecordset.Open("Select * from TotalSales", $objConnection,$adOpenStatic,$adLockOptimistic)

$objRecordset.MoveFirst()

do {$objRecordset.Fields.Item("EmployeeName").Value; $objRecordset.MoveNext()} until 
    ($objRecordset.EOF -eq $True)

$objRecordset.Close()
$objConnection.Close()

Open in new window

0
 
LVL 11

Author Comment

by:Runrigger
ID: 34978357
Karim, not really what I am looking for at the moment;

Basically we have distributed a database and we want to check for updates made to it and pull an updated version if there is one;

Steps
1) Open database
2) Check for the existence of a file on a specified share
3) If the file exists, open another database and close this one
4) The other database then pulls the new version from the share and then
5) Opens the new version before clocing itself!

Look at Step 3 - Open's another database - it is this one which needs to close immediately if it hasn't been opened from the command line

Whilst the code above helps a little bit towards what we need to do, it doesn't allow me to run a test within the second database to check if it has been opened from a command line of not?
0
 
LVL 11

Author Comment

by:Runrigger
ID: 34978367
There may be a much better solution to this and I don't really know what it is.

I am no longer a developer (haven't been for almost 9 years now), but I have been called upon for a little advice, I can't give it, but I thought you guys might.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Accepted Solution

by:
als315 earned 500 total points
ID: 34978402
You can use parameters in command line:
"c:\Program Files\Microsoft Office\MSACCESS.EXE"  "c:\MyDB.mdb" /cmd 1
In code you can get it with Command:
    Dim CmdLine
    CmdLine = Trim(Command())
If len(CmdLine) = 0 then docmd.quit
0
 
LVL 40

Expert Comment

by:als315
ID: 34978413
Use autoexec macro for starting your sub.
0
 
LVL 11

Author Comment

by:Runrigger
ID: 34978646
Excellent, that worked a treat, thank you
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question