Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code Advice (A2k)

    Can the following code be edited in such a way to check if any of the folders are missing and create them individually.
    Current situation, if C:BICImage exists already on first start-up, the rest of the folders do not get created.
    I think I need something before each if DIR command

    <pre>Private Sub Form_Load()
    Dim strFolderPath As String, strMainFolder As String, strSubFolder As String
    On Error GoTo ErrHandler
    DoCmd.Hourglass True

    strMainFolder = "C:BICImage"
    strFolderPath = "C:BicImageUtilities"
    strSubFolder = "C:BicImageEstPDF"

    ' Check if BICImages folder exists
    If Dir(strMainFolder, vbDirectory) = "" Then
    MsgBox "Creating Image Folder", , "Set-Up"
    MkDir strMainFolder

    ' Check if Utilities subfolder exists
    If Dir(strFolderPath, vbDirectory) = "" Then
    MsgBox "Creating Utility Folder", , "Set-Up"
    MkDir strFolderPath

    ' Copy files to subfolder
    If Dir(strSubFolder, vbDirectory) = "" Then
    MsgBox "Creating PDF Folder"
    MkDir strSubFolder
    'Copy utility files and images
    MsgBox "Copying Splash Form Image", , "Set-Up"
    FileCopy "L:BICopen.bmp", strFolderPath & "BICopen.bmp"
    MsgBox "Copying Switchboard Image", , "Set-Up"
    FileCopy "L:SBimage.bmp", strFolderPath & "SBimage.bmp"
    MsgBox "Copying Image Transfer Utility", , "Set-Up"
    FileCopy "L:Image_Browser.exe", strFolderPath & "Image_Browser.exe"
    MsgBox "Copying Default PDF Page", , "Set-Up"
    FileCopy "L:BIS.pdf", strSubFolder & "BIS.pdf"

    End If
    End If
    End If
    Me.Picture = "C:BICimageUtilitiesBICopen.bmp"
    Exit Sub
    ErrHandler:
    MsgBox Err.description, vbExclamation
    End Sub</pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Code Advice (A2k)

    Hi Dave,

    Don't nest the If statements:
    <pre>Private Sub Form_Load()
    Dim strFolderPath As String, strMainFolder As String, strSubFolder As String
    On Error GoTo ErrHandler
    DoCmd.Hourglass True

    strMainFolder = "C:BICImage"
    strFolderPath = "C:BicImageUtilities"
    strSubFolder = "C:BicImageEstPDF"

    ' Check if BICImages folder exists
    If Dir(strMainFolder, vbDirectory) = "" Then
    MsgBox "Creating Image Folder", , "Set-Up"
    MkDir strMainFolder
    End If

    ' Check if Utilities subfolder exists
    If Dir(strFolderPath, vbDirectory) = "" Then
    MsgBox "Creating Utility Folder", , "Set-Up"
    MkDir strFolderPath
    End If

    ' Copy files to subfolder
    If Dir(strSubFolder, vbDirectory) = "" Then
    MsgBox "Creating PDF Folder"
    MkDir strSubFolder
    End If

    'Copy utility files and images
    MsgBox "Copying Splash Form Image", , "Set-Up"
    FileCopy "L:BICopen.bmp", strFolderPath & "BICopen.bmp"
    MsgBox "Copying Switchboard Image", , "Set-Up"
    FileCopy "L:SBimage.bmp", strFolderPath & "SBimage.bmp"
    MsgBox "Copying Image Transfer Utility", , "Set-Up"
    FileCopy "L:Image_Browser.exe", strFolderPath & "Image_Browser.exe"
    MsgBox "Copying Default PDF Page", , "Set-Up"
    FileCopy "L:BIS.pdf", strSubFolder & "BIS.pdf"

    Me.Picture = "C:BICimageUtilitiesBICopen.bmp"
    Exit Sub

    ErrHandler:
    MsgBox Err.description, vbExclamation
    End Sub</pre>


  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code Advice (A2k)

    Hans
    Thanks, the folder part of the code works fine but, each msgbox appears each time the database is opened.
    I tried to check if each image or utility existed also, but get type mismatch:

    <pre>'Copy utility files and images
    If strFolderPath & "BICopen.bmp" = 0 Then
    MsgBox "Copying Splash Form Image", , "Set-Up"
    FileCopy "L:BICopen.bmp", strFolderPath & "BICopen.bmp"
    End If</pre>


    Should I have enclosed with double quotes or Chr(34) on the image name , "BICopen.bmp"

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Code Advice (A2k)

    The comparison strFolderPath & "BICopen.bmp" = 0 doesn't make sense. Filename = 0? <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>
    Use this instead:<pre>If Dir(strFolderPath & "BICopen.bmp") = "" Then</pre>


  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code Advice (A2k)

    Perfect.
    I wasn't sure because of handling system folders, whether there text values could be "" or not.
    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •