Syntax for renaming a file on opening a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have been putting together the pieces to shut down an Access application
remotely (Article ID 304408), in which there's a hidden form with code that
starts a countdown for shutdown if a file of a certain name is missing.

I have a button for the DB admin to use to change the name of the file
(UsersOn to UsersOff), to start the shutdown. (This works) What I can't get
working is code in the OnOpen event of the hidden form that automaticallly
renames the file to UsersOn if its name is UsersOff. Here's what I have:

Private Sub Form_Open(Cancel As Integer)
Dim strFileName As String
strFileName = Dir("\\Mvnf02\Csenet\Service Requests Admin\Kickoff
Users\UsersOff.txt")
'Resets text file name to give users uninterrupted access to the database
If strFileName = "\\Mvnf02\Csenet\Service Requests Admin\Kickoff
Users\UsersOff.txt" Then
Name "\\Mvnf02\Csenet\Service Requests Admin\Kickoff Users\UsersOff.txt" _
As "\\Mvnf02\Csenet\Service Requests Admin\Kickoff Users\UsersOn.txt"
End If

' Set Count Down variable to false
' on the initial opening of the form.
boolCountDown = False

The Name...As syntax works on the OnClick event of a button, but did not
"travel well" to this use. Would appreciate suggestions.
 
Using the Dir function only returns the filename, not the full path (and
only if the file exists).

In other words,

strFileName = Dir("\\Mvnf02\Csenet\Service Requests Admin\Kickoff
Users\UsersOff.txt")

will set strFileName to "UsersOff.txt" if the file exists, and to a
zero-length string ("") if it doesn't exist.

Try:

Dim strFileName As String

strFileName = Dir("\\Mvnf02\Csenet\Service Requests Admin\Kickoff
Users\UsersOff.txt")
'Resets text file name to give users uninterrupted access to the
database
If Len(strFileName) > 0 Then
Name "\\Mvnf02\Csenet\Service Requests Admin\Kickoff Users\UsersOff.txt"
_
As "\\Mvnf02\Csenet\Service Requests Admin\Kickoff
Users\UsersOn.txt"
End If
 
Works perfectly. Thank you so much.
--
susan


Douglas J. Steele said:
Using the Dir function only returns the filename, not the full path (and
only if the file exists).

In other words,

strFileName = Dir("\\Mvnf02\Csenet\Service Requests Admin\Kickoff
Users\UsersOff.txt")

will set strFileName to "UsersOff.txt" if the file exists, and to a
zero-length string ("") if it doesn't exist.

Try:

Dim strFileName As String

strFileName = Dir("\\Mvnf02\Csenet\Service Requests Admin\Kickoff
Users\UsersOff.txt")
'Resets text file name to give users uninterrupted access to the
database
If Len(strFileName) > 0 Then
Name "\\Mvnf02\Csenet\Service Requests Admin\Kickoff Users\UsersOff.txt"
_
As "\\Mvnf02\Csenet\Service Requests Admin\Kickoff
Users\UsersOn.txt"
End If
 
Back
Top