Solved

Opening Access via command line

Posted on 2011-02-25
6
341 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
Independent Software Vendors: 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

627 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