Solved

Open Access table from Excel vba - Office 2007

Posted on 2010-09-13
7
808 Views
Last Modified: 2012-05-10
I have s small macro intended to open a table in Access for viewing. The code executes, but the database only remains open long enough to immediately close! How to address so the access table remains visible?
Public Sub open_dbase()



    Dim LPath As String

    Dim LCategoryID As Long



    'Path to Access database

    LPath = Sheet2.Cells(5, 2)



    'Open Access and make visible

    Set oApp = CreateObject("Access.Application")

   



    'Open Access database as defined by LPath variable

    oApp.OpenCurrentDatabase LPath

    oApp.DoCmd.OpenTable "tblRawData", acViewNormal

    oApp.Visible = True

End Sub

Open in new window

0
Comment
Question by:JP_TechGroup
  • 3
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
Comment Utility
Try adding the line of code shown below:


    Dim LPath As String
    Dim LCategoryID As Long

    'Path to Access database
    LPath = Sheet2.Cells(5, 2)

    'Open Access and make visible
    Set oApp = CreateObject("Access.Application")
   

    'Open Access database as defined by LPath variable
    oApp.OpenCurrentDatabase LPath
    oApp.DoCmd.OpenTable "tblRawData", acViewNormal

    oApp.Visible = True
    oApp.UserControl = True   ' ************ ADD THIS LINE

mx
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
what do you want to achieve by opening the table?

if u want the data from it then use a recordset

or are you actually wanting msaccess to open and remain open with that table open
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
Have you double checked that access is still left opened? it might be behind your excel window, check the taskbar
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Closing Comment

by:JP_TechGroup
Comment Utility
That did it. Thanks!
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
You are welcome ...

mx
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
so mx, whats the secret? I gave it a little test from excel and for me db with table remains open, didnt need the usercontrol
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Secret ?
Not sure.  It was the only thing I could think of.  I have in my database loader, which keeps the loaded mdb open, then closes the loader.

mx
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

744 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

9 Experts available now in Live!

Get 1:1 Help Now