Consulting

Results 1 to 4 of 4

Thread: VBA login script help

  1. #1
    VBAX Newbie
    Joined
    Mar 2015
    Posts
    3
    Location

    VBA login script help

    Hi All

    I'm currently making modifications to a login script created by my senior IT colleagues and I've encountered an issue with the syntax that has stopped me in my tracks.

    First and foremost I'm not exactly an expert when it comes to VBA, but I do know the basics.

    First of all, I have created a simplified version of the ones I am having issues with, it is as follows:

    FYI: the pathways/server names and files will be renamed for security reasons.

    strPath = "\\VirtualServer1\Templates\Business Database"
    
    If IfFileExist(strPath) Then
        strUserDatabasePath = "C:\ProgramData\Business Database"
        objFSO.CopyFolder strPath, strUserDatabasePath
    End If
    This syntax works fine, all files are copied without issue.

    However, when it comes to this lot of code:

    strPath = "\\VirtualServer1\templates\Business Database\Graphics"
    If IfFileExist(strPath) Then
        strUserDatabasePath = "C:\ProgramData\Business Database"
        objFSO.CopyFolder strPath, strUserDatabasePath
    End If
    strPath = "\\VirtualServer1\templates\Business Database\Icons"
    If IfFileExist(strPath) Then
        strUserDatabasePath = "C:\ProgramData\Business Database"
        objFSO.CopyFolder strPath, strUserDatabasePath
    End If
    strPath = "\\VirtualServer1\templates\Business Database\Database1.accdb"
    If IfFileExist(strPath) Then
        strUserDatabasePath = "C:\ProgramData\Business Database"
        objFSO.CopyFile strPath, strUserDatabasePath
    End If
    strPath = "\\VirtualServer1\templates\Business Database\Database2.accdb"
    If IfFileExist(strPath) Then
        strUserDatabasePath = "C:\ProgramData\Business Database"
        objFSO.CopyFile strPath, strUserDatabasePath
    End If
    strPath = "\\VirtualServer1\templates\Business Database\Database3.accdb"
    If IfFileExist(strPath) Then
        strUserDatabasePath = "C:\ProgramData\Business Database"
        objFSO.CopyFile strPath, strUserDatabasePath
    End If
    strPath = "\\VirtualServer1\templates\Business Database\Database4.accdb"
    If IfFileExist(strPath) Then
        strUserDatabasePath = "C:\ProgramData\Business Database"
        objFSO.CopyFile strPath, strUserDatabasePath
    End If
    strPath = "\\VirtualServer1\templates\Business Database\Database5.accdb"
    If IfFileExist(strPath) Then
        strUserDatabasePath = "C:\ProgramData\Business Database"
        objFSO.CopyFile strPath, strUserDatabasePath
    End If
    strPath = "\\VirtualServer1\templates\Business Database\Database6.accdb"
    If IfFileExist(strPath) Then
        strUserDatabasePath = "C:\ProgramData\Business Database"
        objFSO.CopyFile strPath, strUserDatabasePath
    End If
    When I run this script, the Business Database folder is created, but the only contents within the folder are the files from the "Icons" and the "Graphics" folder.

    I'm guessing there is any issue with the objFSO.CopyFile portion of the code? I thought this was valid syntax.

    Any help would be greatly appreciated!
    Last edited by xld; 03-06-2015 at 01:59 AM. Reason: Added code tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    25,112
    Location
    If two work it suggests the problem is not with objFSO.CopyFile, but something else. Have you tried stepping through to see what happens?

    BTW, you could simplify the code

    strUserDatabasePath = "C:\ProgramData\Business Database"
    
    strPath = "\\VirtualServer1\templates\Business Database\Graphics"
    If IfFileExist(strPath) Then objFSO.CopyFolder strPath, strUserDatabasePath
    
    strPath = "\\VirtualServer1\templates\Business Database\Icons"
    If IfFileExist(strPath) Then objFSO.CopyFolder strPath, strUserDatabasePath
    
    strPath = "\\VirtualServer1\templates\Business Database\Database1.accdb"
    If IfFileExist(strPath) Then objFSO.CopyFolder strPath, strUserDatabasePath
    
    strPath = "\\VirtualServer1\templates\Business Database\Database2.accdb"
    If IfFileExist(strPath) Then objFSO.CopyFolder strPath, strUserDatabasePath
    
    strPath = "\\VirtualServer1\templates\Business Database\Database3.accdb"
    If IfFileExist(strPath) Then objFSO.CopyFolder strPath, strUserDatabasePath
    
    strPath = "\\VirtualServer1\templates\Business Database\Database4.accdb"
    If IfFileExist(strPath) Then objFSO.CopyFolder strPath, strUserDatabasePath
    
    strPath = "\\VirtualServer1\templates\Business Database\Database5.accdb"
    If IfFileExist(strPath) Then objFSO.CopyFolder strPath, strUserDatabasePath
    
    strPath = "\\VirtualServer1\templates\Business Database\Database6.accdb"
    If IfFileExist(strPath) Then objFSO.CopyFolder strPath, strUserDatabasePath
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Mar 2015
    Posts
    3
    Location
    Hi xld, thanks for the reply.

    I have since shortened the code, and it functions but still not as I want it to. The same files are placed into the "Business Database" folder as was previously i.e files from Icons and graphics are simply dumped into the folder rather than their own seperate folders being created.

    Also, the database files are not being copied in, which is strange because .ico and .bmp files are being dumped.

    Also I did not mention previously .vbs file is running from a batch which is being used on a user level in their profile in active directory.

    I run the batch file and pause it to see any errors, but I am not given any.
    Last edited by McMeevin; 03-08-2015 at 08:13 PM.

  4. #4
    VBAX Newbie
    Joined
    Mar 2015
    Posts
    3
    Location
    Just an update, I got another to work which follows a similar format to what you proposed (xld):

    strUserDatabasePath = "C:\Users\" & strUserName & "\"

    strPath = "\\VirtualServer1\templates\Business Database\Database1.accdb"
    If IfFileExist(strPath) Then objFSO.CopyFile strPath, strUserDatabasePath

    strPath = "\\VirtualServer1\templates\Business Database\Graphics"
    If IfFileExist(strPath) Then objFSO.CopyFolder strPath, strUserDatabasePath

    strPath = "\\VirtualServer1\templates\Business Database\Icons"
    If IfFileExist(strPath) Then objFSO.CopyFolder strPath, strUserDatabasePath
    Yet the previous syntax posted still does not function as intended.
    Last edited by McMeevin; 03-09-2015 at 09:55 PM.

Tags for this Thread

Posting Permissions

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