OpenCurrentDatabase

wjoc1

Registered User.
Local time
Today, 00:05
Joined
Jul 25, 2002
Messages
117
Hi,

I'm trying to use the OpenCurrentDatabase method to open one Access Database from a button in another.

I manage to open this second database ( a lock file is generated ) but it will not actually display it in the Access window.

What am i doing wrong?

Liam
 
I'm guessing you are not using the Visible property of the database.


Example of module:
Code:
Option Explicit
Option Compare Database

Public appAccess As Access.Application

Public Sub OpenADatabase(ByVal strPath As String)
    
    Set appAccess = CreateObject("Access.Application")
     
    With appAccess
        .OpenCurrentDatabase strPath
        .Visible = True
    End With

End Sub
 
Thanks,

The visible property was exactly it. However now I have another small problem. When it opens how do I get the Microsoft Access Window to maximise. It maximises fine when I open the database seperately.

Liam
 
Like this:

Code:
    With appAccess
        .OpenCurrentDatabase strPath
        .Visible = True
        .DoCmd.Maximize
    End With
 
I've tried this and all it seems to do is maximise the opening form/ or the database window if you don't specify a form. This hardly seems right, but that's what's happening?

Liam
 
By Access window I thought you meant the Database window - obviously, now, you mean the application window.

I don't know how to maximise this.
 
Newly opened db will not close

Good news, bad news...

The good news is that the .RunCommand acCmdAppMaximize command will maximize the Access application window.

The bad news is I have to Ctrl Alt Delete the newly opened Access 97 db for it will not close. Same problem whether I use the acCmdAppMaximize command or not. I am using the following code to open another db and the newly opened db will not close...
Code:
Public appAccess As Access.Application

Public Function TestOpenDB()
    Call OpenADatabase("C:\Data\Access\Test.mdb")
End Function

Public Sub OpenADatabase(ByVal strPath As String)
    
    Set appAccess = CreateObject("Access.Application")
     
    With appAccess
        .OpenCurrentDatabase strPath
        .Visible = True
        .RunCommand acCmdAppMaximize
    End With
    
End Sub
Any suggestions on how to cure the db from not closing?

Thanks in advance for your help!
 
ghudson

I tried your code out but it only keeps the database open for a split second. Is there anyway to keep it open?
 
Figured out what I was doing wrong.

Trying to put this into a vbs file. Is that possible?
 
Hi,

I found this thread useful - just a question on Mile-O's comment -
'Set Object as Nothing' - when do we do this - Is it after closing the other Access application and control returns to the main application?

I am new to access 'Programming' and hence please pardon me if the question is too basic.
Priya :o
 
P_Henry said:
I found this thread useful - just a question on Mile-O's comment - 'Set Object as Nothing' - when do we do this - Is it after closing the other Access application and control returns to the main application?

Sorry. I didn't realise there was a new reply/question to this. You use the Set Object = Nothing phrase when finished using an object (at whatever scope) to reclaim the memory it occupied. It's an efficiency measure.
 
It may three yeears old, but this thread has proved very helpful. The database I needed to open is being opened correctly. I still have two questions, though:

1) What is the syntax for running a macro? If I open Database B from within Database A, how can I then run a macro held within Database B? I've tried opening Database B and using the DoCmd.RunMacro "XXX", but I get a message informing me that the macro I specified can't be found. I assume this means it's looking in Database A, as the macro definitely exists in B.

2) Once the macro has run, what is the syntax to close Database B? At present I need to do it manually, which is fine if it's myself who's running the code, but not so good if it's one of the users.

Thanks for any responses.
 
Set a reference to dbB from dbA. Then you should be able to call any code or macros in dbB from dbA.
 
Okay, I have a reference set.

The DoCmd.RunMacro "xxx" still reports the same message. Do I need to refer to it in a different way?

I've tried

DoCmd.RunMacro "xxx"
DoCmd.RunMacro [database B].[xxx"]
DoCmd.RunMacro [Database B].[Macros].[xxx]

but to no avail.
 
I do not use macros. Try creating a public function in dbB [to do what the macro does] and try calling it in dbA.
 
I wouldn't normally get involved with macros, either, but Database B 'belongs' to someone else, so I may not be able to make those sort of changes.

I'll try, though, and update this thread If I get anywhere.

Thanks for the suggestion.
 
Greetings
I found this forum researching a problem I have in an Access application that opens another Access mdb file in order to print a report from that db. I use the OpenCurrentDatabase command, open the report (which gets printed by a routine that pushes it inot PDFWriter and saves it at a specified location, then I use CloseCurrentDatabase. It seems to work ok, except that the lock file remains in place, which is rather inconvenient. I have to log off in order to cause the lock file to be removed.

I'm running Access 2000 SP-3 with Windows XP Version 5.1 SP2

Thanks in advance for any suggestions.
gd
 
Sorry for the thread necromancy, but the basic code in this thread has been both very helpful and very frustrating to me.

I have a database that tracks the work done on other databases. So I currently have a form that pops up the name of the appropriate mdb file, and using the OpenADatabase function above, when the user clicks that they are going to start using it, I go ahead and immediately find and open that database for them. Great.

However, because I want the new database to STAY open, and have the user close it on their own accord (when the minimal work is done), I cannot close and destroy the object. This is causing the .ldb to stick around, and for Windows to still act as though the 2nd mdb is open after the user is done with their work. So at seemingly random intervals, I have to close the initial database down just so Windows can acknowledge me letting go of the 2nd mdb.

Is there a way for me to close and/or destroy the Access.Application object WITHOUT actually closing the 2nd mdb?

ETA: Working in Access 2003.
 
When you open it using the code also use

Application.UserControl = True

then you can destroy your variables without a problem.
 
That simple! Thanks a lot. The help section for UserControl implies that it's a read only variable, not one I can set.

I'm noticing that Application.CloseCurrentDatabase still closes the MDB, but I leave open the newer instance of Access. Do you think if I just Set Application = Nothing without the .CloseCurrentDatabase, it will still fully relinquish control, so I don't have the .ldb and the re-opening problems?
 

Users who are viewing this thread

Back
Top Bottom