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!

close application with command button.

Status
Not open for further replies.

JMal

Programmer
Aug 19, 2004
61
IE
I have a command button on my form which opens a extrenal application when a cammand button is clicked.

-----------------------------------------------------------

Private Sub runapp_Click()
On Error GoTo Err_runapp_Click

Dim stAppName As String

stAppName = "C:\Documents and Settings\PC1\Desktop\App_1.exe"
Call Shell(stAppName, 1)

Exit_runapp_Click:
Exit Sub

Err_runapp_Click:
MsgBox Err.Description
Resume Exit_runapp_Click

End Sub
----------------------------------------------------------

The above works fine but I want to also close this application from my form. Is it possible to close the same application with another command button?

I have tried "Docmd.close" "Docmd.quit" etc. Not having much luck.

Any ideas.

 
Is it possible to close the same application with another command button?
In short, no.


Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Try Creating a Macro that will open the new application and close the present application. And set the button to run this particular macro. This is how I've done it before.
 
Hi Greg,

The following code will shutdown any powerpoint files which are opened fro a command button on a form.

-------------------------------------------------

Private Sub CmdClosePP_Click()
Dim objPPApp As New PowerPoint.Application
Dim strMessage As String
Dim intOptions As Integer 'DECLARATION OF VALUES
Dim bytChoice As Byte

'MESSAGE BOX TEXT TO VERIFY ACTION

strMessage = "This will Close the Presentation Without Saving it" & _
vbCrLf & "" & _
vbCrLf & "Are you sure you wish to continue?"

intOptions = vbYesNo
bytChoice = MsgBox(strMessage, 20, "Closing.....ALERT!")

If bytChoice = vbYes Then ' IF THEY CHOOSE YES
' FEATURE IS DELETED

objPPApp.Quit


Else ' IF THEY CHOOSE NO
' FEATURE IS NOT DELETED
'Nothing

End If


-------------------------------------------------

Can this not be adapted to shutdown a non-microsoft application.

Jon
 
Hi Shirley,

I've create a macro to open a application before. I thought this mighy be my solution but tried it and could not figure out how to setup a macro to perform to closing of a application which is running.

Can you explain a little more?
 
I can close Outlook and any other Office apps from within Access, too. I was pretty sure that wasn't what you were asking.



Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Shirley, he doesn't want to close Access. He wants to close the 'other' application.
 
What type of other applications are we talking about? I know that VB coding can be used for any of the Microsoft Office Suite. Each program have VB coding, but different wording for each program. But since Access is part of the suite all the program can communicate with each other.
 
The application I want to close is not an Access database.

All the "Quit" Marco seems to do is close the database with options to save or not save etc. Am I doing something wrong?
 
How would you close this app manually ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,

If you right click, a menu appears giving an option to exit.

I have no problem starting the application, but automating the shutdown is what has me confused.

Any suggestions.

 
I know from a marco created in Excel the the closing code in VB is ActiveWindow.Close
 
Cannot seem to get any result form the ActiveWindow.Close suggestion.

Has anyone anu other suggestions?
 
I found this on the Excel Chat room, see if it will work.
ThisWorkbook.Saved = True just before the Application.Quit line
 
Depends on whether the application utilize VB or SQL, if not no they are not able to communicate. Because Access is mainly VB and SQL.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top