If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > VB File Path Spaces

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-25-11, 11:01
junkbot junkbot is offline
Registered User
 
Join Date: Aug 2011
Posts: 5
VB File Path Spaces

Good Afternoon,

I am using the following script to allow multiple users to login to a database 'front end' (forms, queries, etc) with the table held in another database but link.
However the network drive where the database(s) are held, some of the parent folders have spaces in the names which is returning an error. I'm looking for some help how to correct the script to either allow or remove the spaces so that the database can be opened.

Code:
Set WshNetwork = CreateObject("WScript.Network")
GetUser = WshNetwork.UserName
Set WshNetwork = Nothing

LUName = "computername\folder with spaces\PB_Database_V1.1.mdb"
'Note: or LUName = "UNC Name"
oldname = LUName

newName = Replace(LUName, ".mde", "") & GetUser & ".mde"

retval = 0
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

retval = objFSO.CopyFile(oldname, newName, True)

Set objFSO = Nothing

Dim objShell
Set objShell = CreateObject("Wscript.Shell")

objShell****n "MSAccess.exe " & newName

Set objShell = Nothing
Any help appreciated....

Thanks,

J
Reply With Quote
  #2 (permalink)  
Old 08-25-11, 16:17
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,797
Think about running a command from the command line. If the path contains spaces, you need to use a quoted path name.

When scripting in windows, I believe you'll need to replace
Code:
LUName = "computername\folder with spaces\PB_Database_V1.1.mdb"
(which is the equivalent of computername\folder with spaces\PB_Database_V1.1.mdb)

with

Code:
LUName = """" & "computername\folder with spaces\PB_Database_V1.1.mdb" & """"
OR
Code:
LUName = """computername\folder with spaces\PB_Database_V1.1.mdb"""
either of which are the construction of a string containing "computername\folder with spaces\PB_Database_V1.1.mdb"

Four quotes in a row represents a single quote mark. Two quotes in a row, within a quoted string, are escaped as one quote mark, within the quoted string.

Your string would then contain leading and trailing quote marks, within the string.
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Last edited by loquin; 08-25-11 at 16:24.
Reply With Quote
  #3 (permalink)  
Old 08-26-11, 04:07
junkbot junkbot is offline
Registered User
 
Join Date: Aug 2011
Posts: 5
Thanks loquin

However I'm getting a VB error now for line 15.

Code:
retval = objFSO.CopyFile(oldname, newName, True)
Char 1, bad file name or number, code 800A0034

I have tried both of the suggestions below and they both return the same error.

Do you have any other ideas?

Much appreciated.

Junk
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On