How do I?

Posted on 2001-06-26
Last Modified: 2010-05-02
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.
Question by:mtbuford
LVL 43

Accepted Solution

TimCottee earned 100 total points
ID: 6228117
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"
LVL 20

Expert Comment

ID: 6228183

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

Expert Comment

ID: 6228217
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center


Expert Comment

ID: 6228221
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

Expert Comment

ID: 6228232
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"

Expert Comment

ID: 6228239
Every single day there is a newbie who needs to be told:

"Do NOT post proposed answers. Comments only!"

Expert Comment

ID: 6228550

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question