Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 29th, 2005, 08:46 PM
Registered User
Join Date: Aug 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default getObject() and shell() question using automation


I am trying to open a form in another db (secured with MDW file) from the current db. I managed to do this for an unsecured db with a bit of help from this group. (thx everyone). The code is similar, the only difference is using the shell command (to send the user, pwd and workgroup info) recommended on the micorsoft website.
See: http://support.microsoft.com/default...b;en-us;192919

I find that the getObject() method does not want to work in Access (I understand that the new window must lose focus for the application object to be registered)...still...I replaced this line with Set accObj=New access.application. This way the access window opens however I run into an error trying to open the form.

The error is 2486 - You cannot carry out this action at the present time.
Here is the code...

Public Function openSecuredDBwAutomation()
Dim accObj As Access.application, Msg As String
Dim application As String, dbs As String, workgroup As String
Dim User As String, password As String

Dim strPathToFile As String, strDefaultUser As String 'these will be input params eventually
Dim strDefaultPwd As String, strPathToDatabase As String '...input params later

'this will be removed once these will become input params
strPathToFile = ....'the mdw file
strDefaultUser = .....'the user-- should have Admin priviliges to get access to forms/report
strDefaultPwd = .....'pwd
strPathToDatabase = ....'location of the secured db

' assign to local params
application = "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE"
dbs = strPathToDatabase ' path and name of a secured MDB
workgroup = strPathToFile ' the location of the mdw file
User = strDefaultUser ' username
password = strDefaultPwd ' password

'open applciation with workgoup, user info and pwd
x = Shell(application & " " & Chr(34) & dbs & Chr(34) & " /nostartup /user " & User & _
" /pwd " & password & " /wrkgrp " & Chr(34) & workgroup & Chr(34), vbMinimizedFocus)

'Set accObj = getObject("", "Access.Application") 'this line does not work
Set accObj = New Access.application 'had to resort to this instead

accObj.DoCmd.OpenForm "Form1", acDesign 'open form
MsgBox accObj.Forms("Form1").RecordSource 'return record source

accObj.CloseCurrentDatabase 'close db
Set accObj = Nothing
Exit Function
End Function

The purpose of this function is to return the recordsource of the selected object (form or report) as a string. The inputs are listed above. For simplicity I made them all local for now. The messagebox line will be assigning the recordsource to the function in the end to return the SQL as string.

I am not sure why Access breaks down here, the only thing I can think is that maybe the original database opening the secured one is by default belongs to the default security group, so even though the secured database is open, but its objects are not available to view or manipulate. The other issue maybe that most secured DBs hide their database windows, and it may need to be unhidden before accessing any objects. I tried this but this time Access broke down on this line instead. The error msg here is:

2046 - The command or action 'WindowUnhide' isn't available now.

many thanks.


Similar Threads
Thread Thread Starter Forum Replies Last Post
GetObject jdhock8865 Visual Basic 2005 Basics 2 November 3rd, 2008 09:29 PM
GetObject Trap bostek VBScript 2 November 24th, 2004 02:39 AM
why GetObject with IIS is not working alyeng2000 ASP.NET 1.x and 2.0 Application Design 0 September 15th, 2004 09:00 AM
UCOMIRunningObjectTable.GetObject wstueve C# 0 December 18th, 2003 11:47 AM
Shell Function Question SerranoG Access VBA 4 November 12th, 2003 07:57 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.