PDA

View Full Version : VBA login script help



McMeevin
03-05-2015, 04:50 PM
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!

Bob Phillips
03-06-2015, 02:00 AM
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

McMeevin
03-08-2015, 04:24 PM
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.

McMeevin
03-09-2015, 08:25 PM
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.