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!

One instance of Access required only!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
HI,

I want to be able to only open my database once. Any further attempts to open the database should be met with an error message saying the application is already open.

Can anyone help?

H.
 
Hi,
To prevent anyone else getting access to your database whilst you're in it you can open it exclusivly. To do this when you go to the open dialog box you can choose Exclusivly (check box in Access 97 and on the Open drop down in Access 2000). If you want to access it via a shortcut onthe desk top then you can change the shortcut target to read
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "database path" /excl

The quote marks are important and there is a space between Microsoft and Office.
I hope this helps
Giles.
 
I can't remember where I got this code from so I can't give them credit, but here is the code:

Function IsRunning() as integer
Dim db As Database
Set db = CurrentDB()
If TestDDELink(db.Name) Then
IsRunning = -1
Else
IsRunning =0
End If
End Function

' Helper Function
Function TestDDELink (ByVal strAppName$) As Integer

Dim varDDEChannel
On Error Resume Next
Application.SetOption ("Ignore DDE Requests"), True
varDDEChannel = DDEInitiate("MSAccess", strAppName)

' When the app isn't already running this will error
If Err Then
TestDDELink = False
Else
TestDDELink = True
DDETerminate varDDEChannel
DDETerminateAll
End If
Application.SetOption ("Ignore DDE Requests"), False

End Function

Simply call the IsRunning function from your startup form in your database:

If IsRunning() Then
Application.quit
End If Mike Rohde
"I don't have a god complex, god has a me complex!"
 
The DDE approach works well and there is a MS Knowledge Base article ACC: How to Determine If a Specific Windows Program Is Running (Q88167) which shows a Windows API approach.

Both these approaches are fine for displaying a message and closing down. However, I would like to switch to the application automatically rather than make the user answer msgboxes and switch to the open application using mouse clicks. Any ideas?

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top