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

warding off multiple instances of Access

Status
Not open for further replies.

striker73

MIS
Jun 7, 2001
376
US
I am having trouble when I do a mail merge from Access to Word because Word will open up another instance of Access, which throws my whole project off. (I'm not sure why this is happening.) I would like to stop this by placing something like this in the Form_Load() section of my start up form:

If a previous instance of Access is running Then
Unload Me
End if

I don't know any of the VBA syntax and I can't seem to find out how to do this anywhere. Any help would be greatly appreciated!!! Thanks!!!
 
Try this:

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


On your startup form, put:

If IsRunning Then
Application.Quit
End If Mike Rohde
rohdem@marshallengines.com
"If builders built buildings the way programmers wrote programs, the first woodpecker to come along would destroy civilization!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top