Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Opening Access via command line

Posted on 2011-02-25
6
Medium Priority
?
345 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

963 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