Link to home
Start Free TrialLog in
Avatar of mlcktmguy
mlcktmguyFlag for United States of America

asked on

'Name' statement throwing exception in Vista

This is not striclty a VB6.0 question.  I'm pretty sure it has to do with the operating system the app is excuting on but I am hoping that another EE VB developer may have encountered this situation and have suggestions for resolving it.

We developed an app several years ago that is still proving useful and marketable to clients.  When we developed the app we certifeid it on Win XP and Win2000.

In case this matters, the app is packaged for distribution using the latest version of Installsheild.

Now we have clients with VIsta and Windows 7 that would like the app.

There is one statement in the app that runs perfectly in  Win Xp and Win200 that is causing issue in Vista.  The statement is:
Name destFile As sourceFile
which is intended to rename a file to the name of another.  It throws an error 58 'file already exists'.  I included the code snippet in the code window because just above the statement causing the issue I have 'Kill sourceFile' to erase the destination of the rename.  This statement is not throwing an exception but I guess it's possible that it may not be 'killing' the file which could cause the error 58.  That's certainly what the error text seems to indicate.

One of these statements is not doing it's job in Vista.  Does anyone know why, and what I can do to make this code snippet work on a Vista machine?

Kill sourceFile
DoEvents

MsgBox "After Kill sourceFile, before rename destFile as SourceFile," & vbCrLf & _
" destfile = " & destFile & vbCrLf & _
" sourceFile = " & sourceFile

Name destFile As sourceFile

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of bromy2004
bromy2004
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mlcktmguy

ASKER

I understand that is a possibility whic is why I said "I guess it's possible that it may not be 'killing' the file which could cause the error 58." in my originial post.  The question is, even if it is the Kill command not working, why is it onto working in the Vista OS when it works perfectly fine in Windows XP and Windows 2000.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, I got pulled away form this for a couple days.

The 'kill' is using the full path, not just the file name.  The 'name' is alsousing the fullpath.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The file is not being deleted
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I already have an error handler in the routine.  The 'kill' is not throwing an error, it just isn't deleting the file.  As I explained in my first post, it is the statement
'Name destFile As sourceFile' that is throwing the excpetion.

Also, as I mentioned in my first post, this issue does not appear on an XP or Win2000 installation, only on the Vista installation.

For reference I included all of my code with the debugging msgboxes in the code window.  This code has worked perfectly for several years on Xp and Win2000 OS's.
Public Sub Compact_Database(sourceFile As String)

On Error GoTo ErrHandler

Dim jetEngine As JRO.jetEngine
Dim sourceCon As String
Dim destCon As String

'Dim sourceFile As String
Dim destFile As String

'sourceFile = App.Path & dbGTAPName                         ' "\GTAPData.mdb"
'destFile = App.Path & dbGTAPCompress                       ' "\tempgtap.mdb"
destFile = gtapFilesLoc & dbGTAPCompress

Set jetEngine = New JRO.jetEngine

' Engine Type = 4 compacts an Access database in 3.5 format
' Engine Type = 5 compacts an Access database in 4.0 format (default)

sourceCon = strProvider & _
              "Data Source=" & sourceFile & ";" & _
              "Jet OLEDB:Engine Type=5; Jet OLEDB:Database " & strCompactPassword
'
destCon = strProvider & _
            "Data Source=" & destFile & ";" & _
            "Jet OLEDB:Engine Type=5; Jet OLEDB:Database " & strCompactPassword & ";" & _
            "Jet OLEDB:Encrypt Database=True"

'            "Data Source=" & destFile & ";" & _
'            "Jet OLEDB:Engine Type=5; Jet OLEDB: Database " & strCompactPassword & ";" & _
'            "Jet OLEDB:Encrypt Database=True;"
'

'
'openConnection connConnection           ' can't compress if already connected
'
'////////////Debug Code to see what is happening
If Len(Dir(destFile)) > 0 Then
    MsgBox "Before Kill destfile, destfile named " & destFile & ", does exist"
Else
    MsgBox "Before Kill destfile, destfile named " & destFile & ", does NOT exist"
End If
'////////////Debug Code to see what is happening

' Delete tempgtap.mdb if it exists
If Len(Dir(destFile)) > 0 Then
  Kill destFile
End If
'////////////Debug Code to see what is happening
If Len(Dir(destFile)) > 0 Then
    MsgBox "After Kill destfile, destfile named " & destFile & ", does exist, it should not!!"
Else
    MsgBox "After Kill destfile, destfile named " & destFile & ", does NOT exist"
End If
'////////////Debug Code to see what is happening

' Compact the database (makes a new copy)
jetEngine.CompactDatabase sourceCon, destCon

' Delete the source and rename
'////////////Debug Code to see what is happening
If Len(Dir(sourceFile)) > 0 Then
    MsgBox "Before Kill Sourcefile, sourcefile named " & sourceFile & ", does exist"
Else
    MsgBox "Before Kill Sourcefile, sourcefile named " & sourceFile & ", does NOT exist"
End If
'////////////Debug Code to see what is happening

Kill sourceFile
DoEvents
'
'////////////Debug Code to see what is happening
If Len(Dir(sourceFile)) > 0 Then
    MsgBox "After Kill Sourcefile, sourcefile named " & sourceFile & ", does exist"
Else
    MsgBox "After Kill Sourcefile, sourcefile named " & sourceFile & ", does NOT exist"
End If
'////////////Debug Code to see what is happening
'

Name destFile As sourceFile

'
'////////////Debug Code to see what is happening
If Len(Dir(destFile)) > 0 Then
    MsgBox "After Rename Sourcefile, destfile named " & destFile & ", does exist"
Else
    MsgBox "After Rename Sourcefile, destfile named " & destFile & ", does NOT exist"
End If
If Len(Dir(sourceFile)) > 0 Then
    MsgBox "After Rename Sourcefile, sourcefile named " & sourceFile & ", does exist"
Else
    MsgBox "After Rename Sourcefile, sourcefile named " & sourceFile & ", does NOT exist"
End If
'////////////Debug Code to see what is happening
'
'MsgBox "Database compacted successfully.", vbInformation, "System update"

Set jetEngine = Nothing

Exit Sub

ErrHandler:

MsgBox "Error compacting the data: " & Err.Number & vbCrLf & Err.Description, vbCritical, "Error"
 
End Sub

Open in new window

I have been doin research on this issue and noticed that Vista and Windows 7 handle the \Program Files directory differently than XP.  Something about a 'virtual' directory.

I just wante to mention that we are installing our application and application data in a sub-directory of \Program File.  Could this be what is causing our issue?
I will try it and revert I hv Vista on my machine
gowflow
Followup: I uninstalled the app then reinstalled in a subdirectory off of the root of C:

The Kill command and subsequent Name command both work.
Then presume your issue is solved ?
gowflow
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The end result is that we are not installing the data to the \Program Files folder.  I appreciate all of the suggestions and comments.  I distributed the point equally since all the comments led to the eventual solution.
Tks for the nice grade and surely your 'meticulous attribution of marks' which surely shows a high integrity and a respectable person. Pls feel free to let me know anytime you need a help.
rgds/gowflow