How do I?

Read the following:
Private Sub Form_Load()

'Description - PFGPGP Encryption and FTP to Principal
'Created 05/08/01 by Mitchell Buford


OTHRDIR = (Environ$("OTHRDIR") + "\")
Windir = (Environ$("WINDIR") + "\")

' Move old Encrypted Files to Saved.....................

Dim Today As String
Today = Format(Now, "yyyymmdd")
Dim LastMO As String
Dim LastYR As String
Dim THISYR As String
Dim THISDA As String
THISYR = Mid$(Today, 1, 4)
ThisMO = Mid$(Today, 5, 2)
THISDA = Mid$(Today, 7, 2)
LastYR = Val(THISYR)
LastMO = Val(ThisMO) - 1
If LastMO = 0 Then
   LastMO = 12
   LastYR = LastYR - 1
End If
Dim FolderName As String
FolderName = LTrim(Str(LastYR * 100 + LastMO))
gstrMsg = (FolderName)
gstrResponse = MsgBox(gstrMsg)

Name "\\wakelybdc\common\monthend\pfg\" & FolderName & "\agntrept" As "\\wakelypdc\ftp$\pfg"

If Dir("\\wakelypdc\ftp$\pfg\saved\" & FolderName, vbDirectory) = "" Then
   MkDir "\\wakelypdc\ftp$\pfg\saved\" & FolderName
End If

Name "\\wakelypdc\ftp$\pfg\agntrept.pgp" As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\agntrept.pgp"
Name "\\wakelypdc\ftp$\pfg\commrept.pgp" As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\commrept.pgp"
Name "\\wakelypdc\ftp$\pfg\grpstsum.pgp" As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\grpstsum.pgp"
Name "\\wakelypdc\ftp$\pfg\grpssdet.pgp" As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\grpssdet.pgp"

The IF statement I have for the directory, how do I do this with files?  If they are not there or not there how do I make the program skip over and go the next command instead of a runtime error.
Who is Participating?
TimCotteeConnect With a Mentor Head of Software ServicesCommented:
If Dir("\\wakelypdc\ftp$\pfg\saved\" & FolderName, vbDirectory) = "" Then
  MkDir "\\wakelypdc\ftp$\pfg\saved\" & FolderName
End If

If Dir("\\wakelypdc\ftp$\pfg\agntrept.pgp") Then Name "\\wakelypdc\ftp$\pfg\agntrept.pgp" As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\agntrept.pgp"
IF Dir("\\wakelypdc\ftp$\pfg\commrept.pgp") Then Name "\\wakelypdc\ftp$\pfg\commrept.pgp" As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\commrept.pgp"
If Dir("\\wakelypdc\ftp$\pfg\grpstsum.pgp") Then Name "\\wakelypdc\ftp$\pfg\grpstsum.pgp" As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\grpstsum.pgp"
If Dir("\\wakelypdc\ftp$\pfg\grpssdet.pgp") Then Name "\\wakelypdc\ftp$\pfg\grpssdet.pgp" As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\grpssdet.pgp"

Member Name mtbuford
Date Account Created 09/17/99
Knowledgebase Stats:    
Questions Asked 49
Last 10 Grades Given A A A B A A A A A A  
Question Grading Record 18 Answers Graded / 19 Answers Received

And see
I'm not sure if you want to check if the files exist in the destination you want to skip or not, or if there not in the origin

TimCottee's comment will not copy a file if it is not the the Origin Directory for the files.

this will copy only existing file

FileToCopy = Dir("\\wakelypdc\ftp$\pfg\*.pgp")
do while FileToCopy > ""
     ' Check if File is there and Delete if necessary
     if dir("\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\" & FileToCopy) then
          Kill "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\" & FileToCopy
     End If
     Name "\\wakelypdc\ftp$\pfg\" & FileToCopy As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\" & FileToCopy
     FileToCopy = Dir

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Add this to your code:
DocName = Dir("C:\Files\" & FileName & "." & FileType)
    If DocName <> "" Then
        Call StartDoc(SourceName, DocName)
        MsgBox ("No files found by the name of " & FileName & "." & FileType & " in the folder of C:\Files\")
    End If

This is the function it calls
Function StartDoc(SourceName As String, DocName As String)
    Dim FilePath
    On Error GoTo StartDoc_Error
    FilePath = SourceName & " C:\Files\" & DocName
    StartDoc = Shell(FilePath, vbNormalFocus)
    Exit Function
        MsgBox "Error: " & Err & " " & Error
        Exit Function
End Function
On Error Resume Next
Name "\\wakelypdc\ftp$\pfg\agntrept.pgp" As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\agntrept.pgp"
Name "\\wakelypdc\ftp$\pfg\commrept.pgp" As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\commrept.pgp"
Name "\\wakelypdc\ftp$\pfg\grpstsum.pgp" As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\grpstsum.pgp"
Name "\\wakelypdc\ftp$\pfg\grpssdet.pgp" As "\\wakelypdc\ftp$\pfg\saved\" & FolderName & "\grpssdet.pgp"
Every single day there is a newbie who needs to be told:

"Do NOT post proposed answers. Comments only!"

You have asked 49 questions within Experts-Exchange, yet only closed/awarded 19 of them, despite expert input and follow up requests to return and close.  The options at this point are:

1. Award points to the Expert who provided an answer, or who helped you most. Do this by clicking on the "Accept Comment as Answer" button that lies above and to the right of the appropriate expert's name.

2. PAQ the question because the information might be useful to others, but was not useful to you. To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

3. Delete the question because it is of no value to you or to anyone else.  To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

If you elect for option 2 or 3, all you need to do is post right here as a comment, and I will take care of the rest.  We also request that you review any other open questions you might have and deal with them as necessary.




Hi Experts:

In the event that the Asker does not respond, I would very much appreciate your opinions as to which Expert ought to receive points (if any) as a result of this question.  Likewise, you can also suggest that I PAQ or delete the question.

Experts, please do not add further "answer" information to this question.  I will be back in about one week to finalize this question, earlier if comments received.

Thank you everyone.

Community Support Moderator @ Experts Exchange
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.