Share via

3151 connection error

Anonymous
2011-03-19T20:21:38+00:00

From my VBA Code, I need to open a backend DB that has a form that runs on opening  by virtue of Current Database option "Display Form" being set to open the form "closeform".

Form "closeform" shuts the BE down immediately to prevent people from accessing it other than via the FE, which has a bypass function. (It runs "DoCmd.Close acForm, "CloseForm", acSaveYes" and "DoCmd.quit acExit".)

I need to know how to open the BE with VBA (so I can check if I need to add a field). Right now I'm trying to use the code below, but I keep getting this error (Run-time error '3151':ODBC-connection to <database> failed).

I'm thinking the problem might be connected with the way "closeform" behaves. But even if the connection problem isn't due to this feature, I need a way to block "closeform" so I can work with the DB once it's open.

So two questions:

--how can I get the connection?

--how can I programmatically change the "Display Form" setting so I can work with the BE?

Thanks.

Option Compare Database

Option Explicit

Public Sub DBConnect()

  Dim dbBE As dao.Database

  Dim strDBName As String

  strDBName = CurrentProject.Path & "\theBE.accdb"

  Set dbBE = OpenDatabase(strDBName,false ,false ,"PASSWORD=nnnnnn")

  'Debug.Print strDBName

End Sub

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2011-03-20T01:11:09+00:00

    This page has some specifications:

    http://www.connectionstrings.com/access-2007

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-03-20T00:01:20+00:00

    I figured it out. Needed

    dim ws as workspace

    Set ws = DBEngine.Workspaces(0)

    Set dbBe = ws.OpenDatabase(strDBName,false ,false ,";PWD=nnnnnn")

    I don't see any explanation anywhere why its ";PWD" rather than "PASSWORD", which I think I see in some examples. And why the ';'?

    Was this answer helpful?

    0 comments No comments