|
-
May 9th, 2001, 10:35 AM
#1
Thread Starter
Member
Wierd Error Message!
Hello Gurus,
I wrote an app (app1) that consists of a button which when it is pressed it will execute app2. App2 works perfertly when it is executed on it's own and it automatically connects to an Access Database called SampleDatabase2.mdb once it is started. However, when I execute app2 using app1 using the command:
Call Shell("C:\app2.exe", vbNormalFocus)
a error message dialog box with an "OK" button on it appears saying it
"Can't find SampleDatabase2.mdb"
When I click on the "OK" button the main window for app2 appears but app2 doesn't work because it is not connected to the database.
Is there a particular reason why app2 can't connect to the database when I execute it using the command
Call Shell("C:\app2.exe", vbNormalFocus)
from app1?
This error message is really weird and I would really appreciate it if someone can lend me a hand. Thank you!
Marci Sarwan ([email protected])
-
May 9th, 2001, 10:41 AM
#2
Retired VBF Adm1nistrator
In app2 are you specifying a full path to the database, or just expecting to find it in the current directory ?
Because if you just shell something like that, there is a possibility the working directory stays that of App1 ....
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 9th, 2001, 11:00 AM
#3
Thread Starter
Member
Hello plenderj,
I didn't write app2 and I suspect it to find it in the current directory because both app2 and the SampleDatabase.mdb are stored in the same location.
I'm sorry but I'm not sure if I understand your explaination about:
"Because if you just shell something like that, there is a possibility the working directory stays that of App1 ...."
Can you expand on that? Also, is there anything I can do to fix the problem? Thank you!
Marci Sarwan ([email protected])
-
May 9th, 2001, 11:09 AM
#4
Retired VBF Adm1nistrator
Well, app2 might be expecting to be getting the file from "the current directory". If you are inside app1, then the current directory is that of app1. Then if you shell app2, the current directory might still be that of app1.
Try sticking the database into the same dir as app1.
If that doesnt work, there may be some command line parameters you can use with app2.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 9th, 2001, 11:39 AM
#5
Thread Starter
Member
Hello plenderj,
I placed app1 into the same folder as app2 and the SampleDatabase and it worked! Is there another way I can fix this because I sort of don't want to install app1 into the same folder as app2. Thanks!
Marci Sarwan ([email protected])
-
May 9th, 2001, 11:43 AM
#6
Retired VBF Adm1nistrator
Well if you create a shortcut for app1,
then go into the "Shortcut" properties for the shortcut,
then change the "Start In" textbox to the path to app2.
Also, you might want to right click on the label that says "Start In" and read the Whats This help.
It shouls help clear things up.
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 9th, 2001, 11:56 AM
#7
Thread Starter
Member
Hello Jamie,
are you saying I would have to do all these changes manually? This won't work because a few people are going to use my app1 and I was planning on creating a setup file to install app1. Isn't there another command where I can use to call up app2 without making it confused with the directory? Thanks!
Marci Sarwan ([email protected])
-
May 9th, 2001, 12:00 PM
#8
Retired VBF Adm1nistrator
You could use shellexecute to say the default dir ....
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 9th, 2001, 12:08 PM
#9
Thread Starter
Member
Hello Jaime,
I tried that before and it didn't work... This is the command that I used:
Call ShellExecute(0&, vbNullString, "C:\app2.exe", vbNullString, vbNullString, vbNormalFocus)
I had the following module:
Option Explicit
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Const SW_SHOWNORMAL = 1
Marci Sarwan ([email protected])
-
May 9th, 2001, 12:11 PM
#10
Retired VBF Adm1nistrator
Well assuming app2 is in the root directory, try either of these :
Code:
Call ShellExecute(0&, vbNullString, "C:\app2.exe", vbNullString, "C:\", vbNormalFocus)
Call ShellExecute(0&, vbNullString, "C:\app2.exe", vbNullString, "\", vbNormalFocus)
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 9th, 2001, 12:12 PM
#11
Thread Starter
Member
Hello Jaime,
are you any good with creating a setup file? If I was to install app1 into the same directory as app2 how would I make it appear on the start up menu (Start -> Programs). Before I just install it in the directory C:\Program Files. Thanks!
Marci Sarwan ([email protected])
-
May 9th, 2001, 12:15 PM
#12
Retired VBF Adm1nistrator
im going home for the evening now but ill post in the morning
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 9th, 2001, 12:16 PM
#13
Thread Starter
Member
Hello Jaime,
the two code:
Call ShellExecute(0&, vbNullString, "C:\app2.exe", vbNullString, "C:\", vbNormalFocus)
Call ShellExecute(0&, vbNullString, "C:\app2.exe", vbNullString, "\", vbNormalFocus)
didn't work!
Marci Sarwan ([email protected])
-
May 9th, 2001, 12:48 PM
#14
Simpler solution that works perfectly for me:
ChDir GetFolderName(strApp2)
Shell strApp2, vbNormalFocus
'GetFolderName is a function that returns the path where strapp2.exe resides
-
May 9th, 2001, 01:02 PM
#15
Thread Starter
Member
Hello Sarun,
this is what I have:
ChDir GetFolderName("C:\app2.exe")
Shell "C:\app2.exe", vbNormalFocus
and it's complaining about the "GetFolderName" with the following error message:
Compile Error:
Sub or Function not defined
Marci Sarwan ([email protected])
-
May 9th, 2001, 01:15 PM
#16
That is because GetFolderName is a function written by me that returns the path where any file (input) resides - This is not a VB function
-
May 9th, 2001, 01:21 PM
#17
Thread Starter
Member
Hello Sarun,
would it be possible if you can send it to me? I really need to fix this problem and I would really be grateful for your help. Thank you!
Marci Sarwan ([email protected])
-
May 9th, 2001, 01:25 PM
#18
Private Function GetFolderName(strFullPath As String) As String
Dim intPos As Integer
intPos = InStrRev(strFullPath, "\", -1, vbTextCompare)
GetFolderName = Left(strFullPath, intPos - 1)
End Function
strFullPath is a valid filename like in "c:\abc\App2.exe"
-
May 9th, 2001, 01:32 PM
#19
Thread Starter
Member
Hello Sarun,
thanks for the code but unfortunately, I'm still getting the same error.
Marci Sarwan ([email protected])
-
May 9th, 2001, 01:48 PM
#20
ok -
this fn has been declared as Private
so you must be accessing it in a different module/form
If yes, make it Public and
then check the function names to see if they are the same.
-
May 9th, 2001, 01:51 PM
#21
Thread Starter
Member
Hello Sarun,
I only have one form and it's in the same form as my handler. However, I did change it to Public to see if it makes any difference and still I'm getting the error message. Thanks!
Marci Sarwan ([email protected])
-
May 9th, 2001, 01:54 PM
#22
Thread Starter
Member
Hello Sarun,
here's what I have in form1:
Private Sub Command2_Click()
ChDir GetFolderName("C:\app2.exe")
Shell "C:\app2.exe", vbNormalFocus
End Sub
Public Function GetFolderName(strFullPath As String) As String
Dim intPos As Integer
intPos = InStrRev(strFullPath, "\", -1, vbTextCompare)
GetFolderName = Left(strFullPath, intPos - 1)
End Function
Marci Sarwan ([email protected])
-
May 9th, 2001, 03:57 PM
#23
What is the exact error message and where exactly does it scream?? Try to put in a break point and let me know.
I am totally lost since this works just fine on my PC. I really dont see something that would cause an error with these 2 lines.
-
May 9th, 2001, 04:12 PM
#24
Thread Starter
Member
Hello Sarun,
the exact error is "Couldn't find the SampleDatabase.mdb".
This is exactly how it happens. I execute my simple app1 which consists of a button with an event handler which execute app2 when it is pressed. When app2 appears a splash screen pops up and a few second afterward a error dialog box with an "OK" button on it appears which says:
""Couldn't find the SampleDatabase.mdb"
When I press the "OK" button the main window of app2 appears and I have both app1 and app2 on screen. However, app2 doesn't work since it is not connected to the "SampleDatabase.mdb". When I manually execute app2 from window explorer the splash screen pops up and then the main screens appears and the application works.
This is exactly what I have in app1
1 Private Sub Command2_Click()
2
3 ChDir GetFolderName("C:\app2.exe")
4 Shell "C:\app2.exe", vbNormalFocus
5 End Sub
6 Public Function GetFolderName(strFullPath As String) As String
7 Dim intPos As Integer
8 intPos = InStrRev(strFullPath, "\", -1, vbTextCompare)
9 GetFolderName = Left(strFullPath, intPos - 1)
10 End Function
I placed a breakpoint on line 1 and this is the sequence it went through:
1,2,3,6,7,8,9,10,4,5, Splash Screen, Error Message.
I hope you can help. Thank you!
Marci Sarwan ([email protected])
-
May 9th, 2001, 04:19 PM
#25
Thread Starter
Member
Hello Sarun,
I'm not sure if your read some of my earlier helps from Jaimes. He told me to put my app1 in the same directory as app2 and the SampleDatabase.mdb and it worked. However, I don't really want to install app1 into the same directory as app2 and I need to install app1 in C:\program files\App1 so that it appears on the Start menu. app2 and the SampleDatabase.mdb currently are stored in C:\App2\.
Hope you can help. Thank you!
Marci Sarwan ([email protected])
-
May 9th, 2001, 04:21 PM
#26
Post the code from app2.
I dont know how app2 is trying to find the mdb.
Is the error a VB error or a msg displayed by the error handler?
-
May 9th, 2001, 04:32 PM
#27
Thread Starter
Member
Hello Sarun,
unfortunately we don't have the code for app2 because it was written by someone who use to work here and now has moved to another country. The code is no way to be found and all we have is the setup file for it. app2 works perfectly. In my earlier help from Jaime and this is what he suspect:
"Well, app2 might be expecting to be getting the file from "the current directory". If you are inside app1, then the current directory is that of app1. Then if you shell app2, the current directory might still be that of app1.
Try sticking the database into the same dir as app1.
If that doesnt work, there may be some command line parameters you can use with app2"
Thanks!
Marci Sarwan ([email protected])
-
May 9th, 2001, 04:50 PM
#28
Try moving the mdb alone to app1 path - maybe app2 expects the mdb to be in that path.
chdir changes the current direcory to the working dir of app2
-
May 9th, 2001, 05:35 PM
#29
Thread Starter
Member
Hello Sarun,
yes app2 did expected the mdb to be in the same a path. I can't really change this because the setup file for app2 installed the mdb into the same path as app2.
I was thinking since app2 works if I put the exe of app1 into the same path as app2 why don't I create the setup file for app1 and have it install the exe of app1 into the same path of app2. The only problem is I also need to have the setup file set up the program so that it can be access from the Start menu (Start->Programs) as well. I don't know how to create a setup file that will do this do you?
Marci Sarwan ([email protected])
-
May 10th, 2001, 01:56 AM
#30
Retired VBF Adm1nistrator
Well you could do something along these lines :
Code:
'Add Reference to Microsoft Scripting Runtime
Dim fs As FileSystemObject
Private Sub Form_Load()
Set fs = CreateObject("Scripting.FileSystemObject")
If (Dir("c:\DirectoryThatApp2IsIn\app1.exe") = "") Then
fs.CopyFile App.Path & "\app1.exe", "c:\DirectoryThatApp2IsIn\"
Shell "c:\DirectoryThatApp2IsIn\app1.exe"
End
End If
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 10th, 2001, 05:18 AM
#31
Retired VBF Adm1nistrator
Well the idea is that the app will be running from its default install directory. Then, it checks if there is a copy of the same application in the dir of the app which uses the datbase.
If the app isnt there, then we should copy it over and run it from there. Else If the app is already there, just run it anyway.
This is the proper code ;
Code:
Private Sub Form_Load()
Set fs = CreateObject("Scripting.FileSystemObject")
If (Dir("c:\DirectoryThatApp2IsIn\app1.exe") = "") Then
fs.CopyFile App.Path & "\app1.exe", "c:\DirectoryThatApp2IsIn\"
End
End If
Shell "c:\DirectoryThatApp2IsIn\app1.exe"
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
May 10th, 2001, 06:36 AM
#32
Thread Starter
Member
Hello Jaime,
I actually tried that already! i created an exe without any forms called app1helper.exe and I manually copied it into c:\App2. Then
I had app1.exe call app1helper.exe which is in the same directory as app2.exe and the database and it didn't work. The same error appeared. I think my only solution is to literally install app1.exe into c:\App2 then it will work. However, my problem is to be able to access it from the Start Menu (Start->Program). Some people told me it doesn't matter where you install it the setup file automatically setup it up so that you can access it through the Start Menu and others say in order to access it from the Start Menu you must place it in C:\Program Files\.. Do you have any experience with creating setup files? Who is right? Thanks!
Marci Sarwan ([email protected])
-
May 10th, 2001, 07:59 AM
#33
Simply change saruns GetFolderName into this:
Code:
Private Function GetFolderName(strFullPath As String) As String
Dim intPos As Integer
intPos = InStrRev(strFullPath, "\", -1, vbTextCompare)
GetFolderName = Left(strFullPath, intPos) 'take away the -1
End Function
Do not substract 1 from intPos because if your second app resides in the root directory GetFolderName would then return c: instead of c:\ and then ChDir doesn't do anything.
Best regards
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|