Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open An Access Db From VB

Status
Not open for further replies.

vicky666

Programmer
Feb 13, 2003
22
0
0
GB
I am trying to open a specific access database from within vb which runs when i click a button, below is the code i have so far but when it runs it opens access and then shuts it down straight away - any ideas?

Dim appAccess As Object

'Open excel and make visible
Set appAccess = CreateObject("Access.Application")
appAccess.Visible = True

Dim wrkStud As Object
Set wrkStud = appAccess.Application.DBEngine.Workspaces(0).OpenDatabase("C:\Documents and Settings\Administrator\Desktop\UMS\ADReal.mdb")
 
Vicky,

If you don't want an instance of Access to close you need to set the app's UserControl property to TRUE:
Code:
Sub accesstest()
Dim appAccess As Access.Application

    'Open excel and make visible
    Set appAccess = CreateObject("Access.Application")
    appAccess.Visible = True
    appAccess.UserControl = True
    appAccess.OpenCurrentDatabase ("Y:\Data\Access\MailMerge.mdb")

End Sub

Do this AFTER you've set it's Visible property to TRUE - this becomes Read-Only when UserControl = set to TRUE

Reason for this is that the Access object will always close automatically when the object variable it's assigned to is set to nothing or loses its scope - unless you've turned userControl over to the user ... This is *not* the case for either Word or Excel, for some undefinable MS reason ... [bigcheeks]


HTH

Cheers
Nikki
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top