Link to home
Start Free TrialLog in
Avatar of IqbalHamid
IqbalHamid

asked on

Error 2455: You entered an expression that has an invalid reference to the property visible

I get the following error message when using automation to control MSAccess.

"Error 2455: You entered an expression that has an invalid reference to the property visible"

MSAccess has user-level security.  To bypass this using automation, I have shelled out, passing the necessary parameters available when opening MSAccess from command line.  Then I have captured the instance using GetObject(, "Access.Application").

Here's the relevant section of VB code...

    On Error Resume Next
        Set GetoAcc = GetObject(, "Access.Application")
       
        If Err <> 0 Then ' No instance of MS Access is open.
            If IsMissing(varUser) Then varUser = "Admin"
           
            cmdLine = AccPath
            cmdLine = cmdLine & " /nostartup /user " & varUser
           
            If Not IsMissing(varPwd) Then cmdLine = cmdLine & " /pwd " & varPwd
           
            Shell PathName:=cmdLine, WindowStyle:=0
            On Error GoTo WaitForAccess
                Set GetoAcc = GetObject(, "Access.Application")
            On Error Resume Next
        End If
 
        GetoAcc.visible = True


It is on the last line that I get this error message.  HELP!


ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IqbalHamid
IqbalHamid

ASKER

Thank you Jim.  That site was exactly what I required.

Just FYI, I had an MS Access database with BOTH user-level security AND database password set.

It is not possible to directly access OLE automation of MSAccess in such a scenario because it is not possible to pass ALL the necessary security info (UserName, UserPassword and Database Password) via parameters.

I have got around user-level security by shelling out and taking advantage of sitches available during command line launch, THEN capturing that instance using GetObject(, "Access.Application").

I got round the 2nd problem of the database password by opening up the MSAccess instances DBEngine object using DAO, passing in the database password as a parameter there.
Eg:

    GetoAcc.DBEngine.DefaultUser = varUser      
    GetoAcc.DBEngine.DefaultPassword = varPwd
    GetoAcc.DBEngine.SystemDB = sWIF
    Set wks = GetoAcc.DBEngine.CreateWorkspace("wks", varUser, varPwd, dbUseJet)
    Set db = wks.OpenDatabase(sDBPath, False, False, "MS Access;UID=" & varUser & ";PWD=AnUbhalAsAirde")
   
    ' Open the database within oAcc...
    GetoAcc.OpenCurrentDatabase sDBPath, False


I wanted the MSAccess instance invisible most of the time except later when previewing reports I needed to make it temporarily visible but was getting the above error message.

Thanks again for your help!