From: Stewart Berman on 30 Oct 2009 14:04 Access 2007 RunTime The application consists of two database. The first one is launch using RunTime. When the user clicks on the close button I would like to transfer control to the second database. I tried: Application.OpenCurrentDatabase <Full path/name of second database>, True, <Password of Second database> However that throws a you already have the database open error. To make sure something in the first database did not actually have the second one open I built a database that consisted of a single form with the above in its load event and got the same error. The error occurs using the full version of Access 2007 so it is not a RunTime issue. The second database is local on my development machine and not in use by anything when the error is thrown. Is there anyway to transfer control from one database to another without instantiating another instance of Access? Is there anyway to stack application level commands to accomplish the above? For example: CloseCurrentDatabase OpenCurrenDatabase <Full path/name of second database>, True, <Password of Second database>
From: Albert D. Kallal on 30 Oct 2009 16:43 "Stewart Berman" <saberman(a)nospam.nospam> wrote in message news:qgame5d4m9uv0qvldvnf0b23iemb8st2u3(a)4ax.com... > Access 2007 RunTime > > The application consists of two database. The first one is launch using > RunTime. When the user > clicks on the close button I would like to transfer control to the second > database. > > I tried: > Application.OpenCurrentDatabase <Full path/name of second database>, True, > <Password of > Second database> You have to first close the database BEFORE you are able to use the OpenCurrentDatabase command. In effect, that command is ONLY for when you create an NEW instance of ms-access. That means you can really ONLY use that command for an "new" instance, or what we call automaton. However, the problem is that in the runtime it not possible to create another instance of ms-access with code. Actually, the instance does get created, but then it shuts down right away. With the full version of ms-access you can launch ms-access and have the full menus and THEN the user can select/open a database file. In the runtime, if you launch a copy of ms-access, it then right away shuts down if you did not provide a filename at the command line. This is by design because there is no "user interface" that would allow you to open a file. So it makes no sense to launch the runtime without a file name provided (and you can't provide that file name when you automate). So, the runtime by design does NOT allow you to launch a copy and have it sit there and do nothing. > Is there anyway to transfer control from one database to another without > instantiating another > instance of Access? With the runtime. ? What you must do is shell out to another copy and quit the current version. > > Is there anyway to stack application level commands to accomplish the > above? For example: > CloseCurrentDatabase The above CloseCurrentDatabase does work for an instance of ms-access and is in fact required. And, I suppose it likely will work for the CURRENT instance. However you can't execute a close on the current running database and expect the current code to continue to run in the CURRENT instance when it been closed can you! So, again, that close command ONLY makes sense for an automated instance of ms-access. And, as mentioned, if you launch a copy of the runtime without any file name supplied, it instantly shuts down. If you are using the full edition, then automation of a launching an 2nd copy and quitting the current copy of ms-access will work just fine. (it not a big deal memory wise since windows re-uses the current running copy anyway) For the runtime, you can't create instance of ms-access since when you create that instance, it then simply shuts down since (since you can't supply a file name when you create that instance). The simple solution here is to shell out. The code would look like: Const q As String = """" Dim strExe As String Dim strShellProg As String Dim strCurrentDir As String strCurrentDir = currentProject.path & "\" ' get path to msaccess.exe strShellProg = q & SysCmd(acSysCmdAccessDir) & "msaccess.exe" & q strExe = strShellProg strShellProg = strShellProg & " " & q & strCurrentDir & "MyOtherDB.accDB" If Shell(strShellProg, vbNormalFocus) > 0 Then Application.Quit Else MsgBox "Un able to run other program", vbCritical Application.Quit End If The problem here is if that 2nd database has a password, you can't supply the password. So if you want to launch a different database with the runtime, you can't have a password on it. If you using a mdb file, then you CAN USE workgroup security (since /user and /pwd command line switches work). Just keep in mind that the /pwd command line switch is NOT for a database password, but ONLY for the workgroup user name password. This workgroup security IS supported in access 2007 and 2007 runtime, but ONLY if you use mdb file formats, not accDB or accDE formats. -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada pleaseNOOSpamKallal(a)msn.com
|
Pages: 1 Prev: Linked SubForm Issues - cannot edit in subform or move from ma Next: Form Navigation Bar |