chuckcoleman
Registered User.
- Local time
- Today, 03:18
- Joined
- Aug 20, 2010
- Messages
- 380
Hi, I have some code that works, but I need to tweak it to create a folder that uses the data in a field as the folder name. Here is the code that works, (Note, ignore the MsgBox entries I've used for testing):
Dim fs, cf, strFolder
Dim DestPath As String
Dim SrcFile As String
Dim FileName As String
Dim ShowPDF As Boolean
Dim strHyperlinkFile As String
Dim strSelectedFile As String
Dim StrSelectedFileSubDirectory As String
Dim MyDate As String
strFolder = "C:\HOA\Directories\"
Set fs = CreateObject("Scripting.FileSystemObject")
If FolderExists("C:\HOA\Directories") Then
'MsgBox ("The folder exists")
Else
Set cf = fs.CreateFolder(strFolder)
If FolderExists("C:\HOA\Directories") Then
Else
End If
End If
' there is more code that runs query's and creates a PDF file after this.
----------------------------------------------------------------------------------------------------
This is where I'm having trouble. I want this folder created: C:\HOA\Directories\FoxMeadowsWest
Dim fs, cf, strFolder
Dim DestPath As String
Dim SrcFile As String
Dim FileName As String
Dim ShowPDF As Boolean
Dim strHyperlinkFile As String
Dim strSelectedFile As String
Dim StrSelectedFileSubDirectory As String
Dim MyDate As String
Dim HOA As String
Dim strFolder2 As String
HOA = Replace([SubName], " ", "") ' & """" ([SubName] is the name of a field and the data can have spaces in it. 'Replace' removes the spaces. This works)
MsgBox ("1 The HOA is: " & HOA) (The [SubName] data is "Fox Meadows West" and HOA Returns "FoxMeadowsWest" which is correct)
MsgBox ("1a The path is ""C:\HOA\Directories\" & HOA) NOT Correct, returns "C:\HOA\Directories\FoxMeadowsWest
strFolder = """C:\HOA\Directories\" & HOA & """"
strFolder2 = strFolder
' strFolder = "C:\HOA\Directories\" & HOA
MsgBox ("2 The folder is: " & strFolder2) LOOKS correct, returns "C:\HOA\Directories\FoxMeadowsWest"
Set fs = CreateObject("Scripting.FileSystemObject")
If FolderExists(strFolder2) Then
MsgBox ("3 The folder exist") OK
Else
MsgBox ("5 The folder does NOT exist") OK
MsgBox ("6 The value of strFolder: " & strFolder) LOOKS OK, returns "C:\HOA\Directories\FoxMeadowsWest"
Set cf = fs.CreateFolder(strFolder2) ERROR this is when I get "Run-time error 52 Bad file name or number"
If FolderExists("""C:\HOA\Directories\" & HOA) Then
MsgBox ("4 I've created the folder")
Else
End If
End If
More lines of code to run queries and create a PDF
Any ideas?
Chuck
Dim fs, cf, strFolder
Dim DestPath As String
Dim SrcFile As String
Dim FileName As String
Dim ShowPDF As Boolean
Dim strHyperlinkFile As String
Dim strSelectedFile As String
Dim StrSelectedFileSubDirectory As String
Dim MyDate As String
strFolder = "C:\HOA\Directories\"
Set fs = CreateObject("Scripting.FileSystemObject")
If FolderExists("C:\HOA\Directories") Then
'MsgBox ("The folder exists")
Else
Set cf = fs.CreateFolder(strFolder)
If FolderExists("C:\HOA\Directories") Then
Else
End If
End If
' there is more code that runs query's and creates a PDF file after this.
----------------------------------------------------------------------------------------------------
This is where I'm having trouble. I want this folder created: C:\HOA\Directories\FoxMeadowsWest
Dim fs, cf, strFolder
Dim DestPath As String
Dim SrcFile As String
Dim FileName As String
Dim ShowPDF As Boolean
Dim strHyperlinkFile As String
Dim strSelectedFile As String
Dim StrSelectedFileSubDirectory As String
Dim MyDate As String
Dim HOA As String
Dim strFolder2 As String
HOA = Replace([SubName], " ", "") ' & """" ([SubName] is the name of a field and the data can have spaces in it. 'Replace' removes the spaces. This works)
MsgBox ("1 The HOA is: " & HOA) (The [SubName] data is "Fox Meadows West" and HOA Returns "FoxMeadowsWest" which is correct)
MsgBox ("1a The path is ""C:\HOA\Directories\" & HOA) NOT Correct, returns "C:\HOA\Directories\FoxMeadowsWest
strFolder = """C:\HOA\Directories\" & HOA & """"
strFolder2 = strFolder
' strFolder = "C:\HOA\Directories\" & HOA
MsgBox ("2 The folder is: " & strFolder2) LOOKS correct, returns "C:\HOA\Directories\FoxMeadowsWest"
Set fs = CreateObject("Scripting.FileSystemObject")
If FolderExists(strFolder2) Then
MsgBox ("3 The folder exist") OK
Else
MsgBox ("5 The folder does NOT exist") OK
MsgBox ("6 The value of strFolder: " & strFolder) LOOKS OK, returns "C:\HOA\Directories\FoxMeadowsWest"
Set cf = fs.CreateFolder(strFolder2) ERROR this is when I get "Run-time error 52 Bad file name or number"
If FolderExists("""C:\HOA\Directories\" & HOA) Then
MsgBox ("4 I've created the folder")
Else
End If
End If
More lines of code to run queries and create a PDF
Any ideas?
Chuck