Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2004

    Unanswered: Opening a form in another secured database

    MS Access 2000 automation.
    Can anybody tell me how I open a form in another secured Access db??

    I have seen examples on how to open a secured db and I have seen examples on how to open a form in another database, by no examples of the combination of thees 2 situations??


  2. #2
    Join Date
    Mar 2003
    The Bottom of The Barrel
    Provided Answers: 1
    By definition you're not going to be able to open anything in "another" secured database. In order to open a secured database you have to use the mdw that was used to create that database.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Nov 2004

    Question Yes I can!

    I have seen, amongst a lot, 2 examples:
    The first one tells me how to open a secured database, but not how to open a form inside that database.
    The second one tells me how to open a form in a not secured database, but it seems to be impossible to use that code if the database is secured.


    Ex 1:

    Option Explicit
    Dim objAccess as Object

    'This procedure sets a module-level variable, objAccess, to refer to
    'an instance of Microsoft Access. The code first tries to use GetObject
    'to refer to an instance that might already be open. If an instance is
    'not already open, the Shell() function opens a new instance and
    'specifies the user and password, based on the arguments passed to the
    'Calling example: OpenSecured varUser:="Admin", varPw:=""

    Sub OpenSecured(Optional varUser As Variant, Optional varPw As Variant)
    Dim cmd As String
    On Error Resume Next
    Set objAccess = GetObject(, "Access.Application")
    If Err <> 0 Then 'no instance of Access is open
    If IsMissing(varUser) Then varUser = "Admin"
    cmd = "C:\Program Files\Microsoft Office\Office\MSAccess.exe"
    cmd = cmd & " /nostartup /user " & varUser
    If Not IsMissing(varPw) Then cmd = cmd & " /pwd " & varPw
    Shell pathname:=cmd, windowstyle:=6
    Do 'Wait for shelled process to finish.
    Err = 0
    Set objAccess = GetObject(, "Access.Application")
    Loop While Err <> 0
    End If
    End Sub

    Ex 2:
    Function fOpenRemoteForm(strMDB As String, _
    strForm As String, _
    Optional intView As Variant) _
    As Boolean
    Dim objAccess As Access.application
    Dim lngRet As Long

    On Error GoTo fOpenRemoteForm_Err

    If IsMissing(intView) Then intView = acViewNormal

    If Len(Dir(strMDB)) > 0 Then
    Set objAccess = New Access.application
    With objAccess
    lngRet = apiSetForegroundWindow(.hWndAccessApp)
    lngRet = apiShowWindow(.hWndAccessApp, SW_NORMAL)
    'the first call to ShowWindow doesn't seem to do anything
    lngRet = apiShowWindow(.hWndAccessApp, SW_NORMAL)
    .OpenCurrentDatabase strMDB
    .DoCmd.OpenForm strForm, intView
    Do While Len(.CurrentDb.Name) > 0
    End With
    End If
    On Error Resume Next
    Set objAccess = Nothing
    Exit Function
    fOpenRemoteForm = False
    Select Case Err.Number
    Case 7866:
    'mdb is already exclusively opened
    MsgBox "The database you specified " & vbCrLf & strMDB & _
    vbCrLf & "is currently open in exclusive mode. " & vbCrLf _
    & vbCrLf & "Please reopen in shared mode and try again", _
    vbExclamation + vbOKOnly, "Could not open database."
    Case 2102:
    'form doesn't exist
    MsgBox "The Form '" & strForm & _
    "' doesn't exist in the Database " _
    & vbCrLf & strMDB, _
    vbExclamation + vbOKOnly, "Form not found"
    Case 7952:
    'user closed mdb
    fOpenRemoteForm = True
    Case Else:
    MsgBox "Error#: " & Err.Number & vbCrLf & Err.Description, _
    vbCritical + vbOKOnly, "Runtime error"
    End Select
    Resume fOpenRemoteForm_Exit
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts