Code suddenly doesn't work anymore (1 Viewer)

Guus2005

AWF VIP
Local time
Today, 19:42
Joined
Jun 26, 2007
Messages
2,645
I have this code to open a file with the default application based on the extension.
It is usually used for a .txt extension and it opened Notepad++.
Code:
Public Sub openScriptInDefaultEditor(strFilename As String)
    'File is opened in default editor

    Dim strFullPath As String
    Dim fso As Object
    Set fso = CreateObject("Shell.Application")
    
    strFullPath = Nz(DLookup("Pad", "tblScript", "Projectnaam = '" & TempVars!Projectnaam & "' and Scriptnaam = '" & strFilename& "'"), "")
    
    If Len(strFullPath) > 0 Then
        If FileExist(strFullPath) Then
            fso.Open strFullPath
        Else
            MsgBox "File not found at location:" & vbCrLf & strFullPath, vbExclamation, "Oops"
        End If
    Else
        MsgBox "Path is empty, no file found", vbExclamation, "???"
    End If

End Sub

It stopped working and i don't know why??

If anyone can tell me what's wrong with the code which i didn't change, why it stopped working or if you have an alternative, please let me know!

Thanks for your time.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 18:42
Joined
Jul 9, 2003
Messages
16,244
I suggest that you replace the concatenated path "strFullPath" with a hard-coded path so you know exactly where the code is looking for the file, Here:-

If FileExist(strFullPath) Then

And report back the result...
 

Guus2005

AWF VIP
Local time
Today, 19:42
Joined
Jun 26, 2007
Messages
2,645
I got a working path when i look at the contents of the strFullPath variable.

?strFullPath
c:\Temp\Scripts\Slablaadje.txt

When i open notepad++ en open a file and paste in the path, it opens nicely.

The code worked for a few months, and now it doesn't.
Code:
fso.Open "c:\Temp\Scripts\Slablaadje.txt"
Doesn't give me anything. Not even an errorcode.

EDIT: Forgot to mention: Sometimes decompiling fixes the problem by showing where there is an issue. (which you didn't find in the compiled version). But that didn't do anything for me.
 
Last edited:

Minty

AWF VIP
Local time
Today, 18:42
Joined
Jul 26, 2013
Messages
10,355
There was a windoze update in the last few days?
Possible Coincidence?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 18:42
Joined
Sep 12, 2006
Messages
15,614
maybe you have associated a .txt file with a different default app, somehow. Would that cause this issue?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:42
Joined
Oct 29, 2018
Messages
21,358
Hi. Just had to ask, since we can't see what you're seeing. Doesn't work means nothing happens or you get an error?
 

Guus2005

AWF VIP
Local time
Today, 19:42
Joined
Jun 26, 2007
Messages
2,645
If a text file was associated with e.g. UltraEdit, UltraEdit would be used to open the text file.
Ofcourse i rebooted (a few times by now) and even reinstalled the Notepad++ app which i normally use for text files.

Looks like im the only one ever to come accros this kind of problem. Shoot.

When i am debugging and put a breakpoint on the fso..Open line (with a single dot), F8 brings me neatly to the next line to be executed.
As if the line didn't exist.

I am at a loss.
Is there another way to open a text file using the default app?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:42
Joined
Oct 29, 2018
Messages
21,358
If a text file was associated with e.g. UltraEdit, UltraEdit would be used to open the text file.
Ofcourse i rebooted (a few times by now) and even reinstalled the Notepad++ app which i normally use for text files.

Looks like im the only one ever to come accros this kind of problem. Shoot.

When i am debugging and put a breakpoint on the fso..Open line (with a single dot), F8 brings me neatly to the next line to be executed.
As if the line didn't exist.

I am at a loss.
Is there another way to open a text file using the default app?
Have you tried ShellExecute?
 

vba_php

Forum Troll
Local time
Today, 13:42
Joined
Oct 6, 2019
Messages
2,884
guus,

have you tried the actual "file system object" that is part of VBA? i believe the method is called "openTextfile". that's not the fso you had declared. you declared the dos shell, right?
 

vba_php

Forum Troll
Local time
Today, 13:42
Joined
Oct 6, 2019
Messages
2,884
furthermore, another method is to just use DOS directly to open it by running a command in the invisible command line through VBA
 

Users who are viewing this thread

Top Bottom