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

Opens multiple copies of application

Status
Not open for further replies.

BusMgr

IS-IT--Management
Aug 21, 2001
138
US
I have a cmd button on a form that searches for and opens an external application. It appears to find the application okay, but it opens multiple copies of the application (2 - 5 copies to date), even though there is only one copy of the .exe file on the computer.

My code is as follows -

Private Sub cmdReedHyd_Click()
On Error GoTo Err_cmdReedHyd_Click
'Part I
'Perform simple search using the FileSearch object.

Dim varItem As Variant

With Application.FileSearch
.NewSearch
.Filename = "Hyd.EXE"
.LookIn = "C:\"
.SearchSubFolders = True
.Execute

'Part II
For Each varItem In .FoundFiles

Call Shell(varItem, 1)

Next varItem

End With

Exit_cmdReedHyd_Click:
Exit Sub

Err_cmdReedHyd_Click:
MsgBox Err.Description
Resume Exit_cmdReedHyd_Click

End Sub

Since I just use the 'Exit' button on the application, do I need to end or set to null the application in my VBA code?

Any help would be appreciated.

Thanks
BusMgr
 
Gonna take a shot in the dark here and give you my two cents worth...

You are recursively searching the C: drive for this app....First off, that could potentially take a while....Why do that much searching? Find a good default location for the file and put it there....

Second, during the search it is highly likely that WIndows is finding "pointers" (i.e. shortcuts, referential links) to the .exe, and because you end your code with a FOR EACH...IN Statement, Access is opening each of the references...and they all point back to the .exe. Suggest you just have the db search for the .exe....at first finding, execute your shell command and then exit sub, right then and there.....no more searching, no more calls.....

My third and final suggestion is one of performance...you say this is run from a command button.....so the user has to wait for the app to be found, then executed....I would create a global variable in my main form for the database, and have that form run the search code when the form opens, and fill the variable. The when the user clicks the button, just execute the shell command with the variable as the path of the file to open....

Just my couple of dimes! Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top