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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a access file from vb6

Status
Not open for further replies.

seanybravo

IS-IT--Management
Sep 24, 2003
89
0
0
GB
I want to open an access database from within vb6 could anyone help me on how to do this. I have looked at previous posts and have found examples for excel and word but no Access.

Thanks

Sean Williams
 
What do you want to do with your Access file?
get at table data, show the access app, run a macro or print a form???

 
Hi Sean,

Don't know if this is how you want to open Access but this thread might be of use to you.

thread709-931202

Hope this helps

Harleyquinn
 
What do you want to do with your Access file?
get at table data, show the access app, run a macro or print a form???

 
Thanks Both for you prompt replies. I have managed to get something working now, however I am having trouble, as the database I want to open is open with my app.

Basically I have designed an application than managed databases however due to time constraints and ever increasing additions I decided that any unusual requests to the data could be done manually in access to save me reinventing the wheel for one off requirements. So I have added an open in access button using this code:

'Must close the current connection first
rsData.Close
cnData.Close
‘unsure abaout this as I want to open the database again when I am back in my app
‘Set rsData = Nothing
‘Set cnData = Nothing

If CurrentDatabase <> "" Then
'Open in Access Code
Dim objAccess As Object
Set objAccess = CreateObject("Access.Application")
objAccess.openCurrentDatabase StrDataPath & "\" & CurrentDatabase & ".mdb", False

Else
MsgBox ("You must first select a directory from the drop down list"), vbInformation
End If

But the database will not open and I get the error:

Run-time error ‘7866’

Microsoft Access can’t open the database because it is missing, or opened exclusively by another user.

My app manages and opens databases from a dropdown list and opens them when they are selected. So after I open a database with my Open In Access button the list is reset and the user will have to close the database that is open in access and reselect it in my app to use it again.

Any ideas to help me out?
 
Sean,

I see where your killing both the connection and recordset but are you closing out the instance of the access application. Check you task manager and see if MSACCESS.exe is still there running. If it is you file is locked open in the applications instance. I forget the acual code but it should be somthing like myaccess.application.quit.


Hope this helps

Dan
 
I have vb6 code for opening a shelling to a database, including finding it by the shortcut and opening it with any extra bits there, and adding a password if necessary. But this code is designed to shell out, not give you an object with which to work programmatically. If this code would be of any help, please let me know.

Ahliana
Argue for your limitations and, sure enough, they're yours! - Richard Bach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top