Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Opening Access via command line

Posted on 2011-02-25
6
Medium Priority
?
343 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 40

Accepted Solution

by:
als315 earned 2000 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

705 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