Solved

Opening Access via command line

Posted on 2011-02-25
6
336 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
  • 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 39

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 39

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now