R
Robert Bonds
Need a bit of help, please, with some VBA code that I've written in Microsoft
Outlook 2007. It is intended to call up a specific Microsoft Access database
and open a particular form and subform, so that it can then go on to take
various actions based on the values from Outlook. Here's the basic code:
------
Sub SwitchToProjects()
Dim appAccess As Access.Application
Dim ThisDatabaseFileName As String
ThisDatabaseFileName = "C:\myFile.mdb"
Set appAccess = GetObject(ThisDatabaseFileName, "Access.Application")
appAccess.Forms!frmHome!frmSplash.Visible = False
appAccess.Forms!frmHome!frmCompanies.Visible = False
appAccess.Forms!frmHome!frmProjects.Visible = True
'Do additional actions here
End Sub
------
The code works fine, except that it opens a new instance of Access and the
database every time it's called. What I'm trying to write is some kind of IF
THEN clause at the beginning of this procedure that will test whether that
particular database is already open, and if so, simply switch to it and open
the correct form.
I've tried every syntax I can think of or learn about, so far without
success. At one user's group on line I was able to find a procedure using the
Windows API (which I'm not too familiar with yet) that will check whether
Access is running and, if so, switch the focus over to the Access window.
That works, but it doesn't seem to be able to distinguish among Access
windows if more than one database is open. And even if it does switch to the
correct database, I need some way to actually work with it... and so far I
haven't been able to find the syntax to have a reference to the Access object
without opening it again.
Any suggestions would be most welcome. Thank you!
Outlook 2007. It is intended to call up a specific Microsoft Access database
and open a particular form and subform, so that it can then go on to take
various actions based on the values from Outlook. Here's the basic code:
------
Sub SwitchToProjects()
Dim appAccess As Access.Application
Dim ThisDatabaseFileName As String
ThisDatabaseFileName = "C:\myFile.mdb"
Set appAccess = GetObject(ThisDatabaseFileName, "Access.Application")
appAccess.Forms!frmHome!frmSplash.Visible = False
appAccess.Forms!frmHome!frmCompanies.Visible = False
appAccess.Forms!frmHome!frmProjects.Visible = True
'Do additional actions here
End Sub
------
The code works fine, except that it opens a new instance of Access and the
database every time it's called. What I'm trying to write is some kind of IF
THEN clause at the beginning of this procedure that will test whether that
particular database is already open, and if so, simply switch to it and open
the correct form.
I've tried every syntax I can think of or learn about, so far without
success. At one user's group on line I was able to find a procedure using the
Windows API (which I'm not too familiar with yet) that will check whether
Access is running and, if so, switch the focus over to the Access window.
That works, but it doesn't seem to be able to distinguish among Access
windows if more than one database is open. And even if it does switch to the
correct database, I need some way to actually work with it... and so far I
haven't been able to find the syntax to have a reference to the Access object
without opening it again.
Any suggestions would be most welcome. Thank you!