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

Posted on 2008-11-08
Last Modified: 2012-06-21
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
Question by:Mach1pro
    LVL 74

    Expert Comment

    by:Jeffrey Coachman

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

    LVL 74

    Expert Comment

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

    Error message?
    Screen freeze?
    System crash?

    Please be specific.

    LVL 6

    Accepted Solution

    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) "openAccForm"
    ShowAccess db, 3
    Set db = Nothing

    So now that I've answered my own question, I guess someone can close this
    LVL 74

    Expert Comment

    by:Jeffrey Coachman
    You must click the request attention button.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now