Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 29th, 2005, 08:46 PM
Registered User
 
Join Date: Aug 2005
Location: Toronto,ON, , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default getObject() and shell() question using automation

Hello.

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
accObj.Quit
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.
juneBug

thx
juneBug
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
GetObject jdhock8865 Visual Basic 2005 Basics 2 November 3rd, 2008 08:29 PM
GetObject Trap bostek VBScript 2 November 24th, 2004 01: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 10:47 AM
Shell Function Question SerranoG Access VBA 4 November 12th, 2003 06:57 PM



All times are GMT -4. The time now is 05:19 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.