Solved

opening access programatically without opening its opening forms

Posted on 2013-01-15
9
331 Views
Last Modified: 2013-05-16
hey guys, i have a vbscript that has these lines of code in it:


Set objAccess = CreateObject("Access.Application")
on error resume next
dim strCurrentProjectName
strCurrentProjectName = objaccess.currentproject.name
If err.Number=0 then
&#9;if objaccess.currentproject.name <> "WBR.mdb" then
&#9;&#9;objAccess.OpenCurrentDatabase strNameOfFolderVBScriptIsIn & "WBR.mdb"
&#9;end if
Else
&#9;objAccess.OpenCurrentDatabase strNameOfFolderVBScriptIsIn & "WBR.mdb"
End if

Open in new window


what i'm interested in is - when i open access through VBscript like that, does it open the opening forms as well? cause i'm thinking of putting a synchronise code at the starting form when the user opens the access database BUT if the access database is opened programatically then i don't want to run that synchronise code. so how do i open the database programmatically without opening the opening forms? thanks guys!!
0
Comment
Question by:developingprogrammer
9 Comments
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 38781215
In your Access Database, create a Macro and name it autoexec which should run commands on opening the MDB file.

HTH,

Kent
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38782119
You can either use a macro (I don't generally use macros) or vba code.

The way I do this is that when I want to open the application programmatically, I pass it a parameter, then in my StartUp form, I check to see whether a command line parameter was passed to the application, using the Command() function call.  If so, I bypass that form and process the specific actions the command line parameter used by calling specific functions within the application.  Then I close the application.

The normal syntax for opening Access with a command line parameter would be something like:

"C:\Program Files\Microsoft Office\Office12\MSACCESS.EXE" "C:\YourFileName.accdb" /cmd "Out-of-Variance"

I'm not sure how you would do that using the vbScript
0
 

Author Comment

by:developingprogrammer
ID: 38785455
thanks fyed, your method seems to be the one i'm looking for. but i tried a few ways to run this line of "code" you gave me from vbs and from excel but i can't get it to work. it's supposed to run from a shortcut and that's why i have problems trying to get it running from code. i came across this article but doesn't help much. http://support.microsoft.com/kb/209207

could anyone advise on how to use fyed's method from vbs? thanks guys!!
0
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)

 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 38805967
In the startup code, place something like this:

if Command = "Out-of-Variance" then
     ' what to do if opened programmatically, with /cmd parameter
else
    ' what to do if opened in regular way - display some form etc.
end if

That said, maybe you don't need to open Access at all. If what you need is the data from Access database, you can create ADO object, and open ADO connection to the database as to any other data source, then you can run queries against Access tables and queries in the file, but no Access forms etc will open up.

There's also another option. If in different scenarios you want to open as startup different forms, one way to do it is have no auto-startup form at all, create shortcuts from the forms themselves, and give these shortcuts to the users. Using the shortcut will open the right form directly. You can create shortcuts for all Access objects.
0
 
LVL 84
ID: 38806110
If you want to pass Command line parameters, you'll have to use the Shell command, something like this:

Dim w_shell

Set w_shell = WScript.CreateObject("WScript.Shell")

w_shell.Run "full path to microsoft access.exe " & "full path to the db" & " /cmd YourcommandHere"
0
 
LVL 22

Accepted Solution

by:
Nico Bontenbal earned 500 total points
ID: 38808844
I think you can solve this using the UserControl property:
http://msdn.microsoft.com/en-us/library/office/ff836033.aspx

So in your code between line 2 and 3 add:
objAccess.UserControl = True

Open in new window


In the startup code of your db you can check this property an determine what to do based on this value.
0
 

Author Comment

by:developingprogrammer
ID: 38812924
whao guys, all fantastic fantastic responses. let me try them out next week and get back to yall (a bit under the pump this week!!) = )) thanks guys once again, from first read seems like super fantastic responses to try!!!
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

816 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

8 Experts available now in Live!

Get 1:1 Help Now