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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.


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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

738 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