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

Problem with OpenCurrentDatabase

Status
Not open for further replies.

DanielGreenwood

Technical User
May 9, 2002
21
GB

I'm in the process of upgrading some databases from 97 to 2003 and doing some general tidying up of the code. Currently there is central switchboard which is used to navigate between various databases on the network. It is coded using send keys to open the 'Open Database' dialogue box then type in the location of the required database and then hit enter.

I really want to change this as I can see many possible problems occuring and its just plain messy!

I've tried using the OpenCurrentDatabase method to open a new database when a button is clicked on the form. However all the code does is close the current dbase then seemingly ignores the new location specified and re-opens the same dbase. This is my (very simple) peice of code:

Dim appNew As New Access.Application
Dim strDBFileLocation As String

strDBFileLocation = "\\server\file\Database.mdb"

appNew.OpenCurrentDatabase (strDBFileLocation)

Is there anything I'm missing here?

Your help is much appreciated
 
Hi..

If you have listed all your code , then you are missing a few parts.
The following was taken from HELP, you should look that over again.
' Include following in Declarations section of module.
Dim appAccess As Access.Application

Sub DisplayForm()
' Initialize string to database path.
Const strConPathToSamples = "C:\Program " _
& "Files\Microsoft Office\Office\Samples\Northwind.mdb"

strDB = strConPathToSamples & "Northwind.mdb"
' Create new instance of Microsoft Access.
Set appAccess = _
CreateObject("Access.Application")
' Open database in Microsoft Access window.
appAccess.OpenCurrentDatabase strConPathToSamples
' Open Orders form.
appAccess.DoCmd.OpenForm "Orders"
End Sub

Should pay particular attention to the CreateObject entry

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top