Results 1 to 33 of 33

Thread: Wierd Error Message!

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52

    Angry 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])
    Marci Sarwan

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  8. #8
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    You could use shellexecute to say the default dir ....
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  10. #10
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  11. #11

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  12. #12
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    im going home for the evening now but ill post in the morning
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  13. #13

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  14. #14
    sarun
    Guest
    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

  15. #15

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  16. #16
    sarun
    Guest
    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

  17. #17

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  18. #18
    sarun
    Guest
    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"

  19. #19

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    Hello Sarun,

    thanks for the code but unfortunately, I'm still getting the same error.




    Marci Sarwan ([email protected])
    Marci Sarwan

  20. #20
    sarun
    Guest
    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.

  21. #21

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  22. #22

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  23. #23
    sarun
    Guest
    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.

  24. #24

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  25. #25

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  26. #26
    sarun
    Guest
    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?

  27. #27

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  28. #28
    sarun
    Guest
    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

  29. #29

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  30. #30
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  31. #31
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  32. #32

    Thread Starter
    Member
    Join Date
    Jun 2000
    Location
    Posts
    52
    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])
    Marci Sarwan

  33. #33
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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
  •  



Click Here to Expand Forum to Full Width