[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Need to open a form in Access from a visual basic exe

I Need to be able to open a form in an Access 2007 database from a vb form.
The database WILL already be open, but could be minimized or maximized when the vb form code runs.
So I need specific code to connect to the database and then open the form.
Here's kind of what I'm after, but of course it doesn't work:

Dim Acc As Object, db As Object
Dim strFullPath As String
strFullPath = strDir & "Database Name.accdb"
Set Acc = CreateObject("Access.Application")
Set db = Acc.application.DBEngine.Workspaces(strFullPath)
db.DoCmd.Openform "Name of Access Form"
Set db = Nothing
Set Acc = Nothing
  • 3
1 Solution
Jeffrey CoachmanCommented:

I can't see where you Declared or SET strDir?

Jeffrey CoachmanCommented:
...And explain "EXACTLY" what you mean by: "but of course it doesn't work"

Error message?
Screen freeze?
System crash?

Please be specific.

Mach1proAuthor Commented:
Now that I don't need this code anymore, I found out how to make it work.
I can create a public function within the Access database to open the form. Then in VB, I simply call the access function.
Here's what the VB code looks like:

Dim db As Object
Dim strFullPath As String
Dim strUser As String
strFullPath = strDBFileName
Set db = GetObject(strFullPath)
db.run "openAccForm"
ShowAccess db, 3
Set db = Nothing

So now that I've answered my own question, I guess someone can close this
Jeffrey CoachmanCommented:
You must click the request attention button.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now