deer777
asked on
VBA Code for Access to create and name a folder if it does not exist
I need VBA Code for Access to first check and see if a folder exists and if it does not then create and name it based on the number shown on a textbox on the main form.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There is a simple and direct call for this.
Copy/paste into a new module:
Copy/paste into a new module:
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
Public Sub CreatePath(ByVal Path As String)
If Right(Path, 1) <> "\" Then
Path = Path & "\"
End If
MakeSureDirectoryPathExists Path
End Sub
Then call:CreatePath(Me!YourTextbox.Value)
/gustav
ASKER
Nori
I have input this code but [unothing happens[/u] when I press the button that I put the code on.
The textbox is on the main form.
I have input this code but [unothing happens[/u] when I press the button that I put the code on.
The textbox is on the main form.
ASKER
Nori
I was wrong, it did create the folder as requested.
What I need the code to do now is if it finds it initially, I need it to open it.
If it doesn't find it, I need it to create it and then open it.
What can I add to the code to get it to open the folder if it exists or after it creates it.
I was wrong, it did create the folder as requested.
What I need the code to do now is if it finds it initially, I need it to open it.
If it doesn't find it, I need it to create it and then open it.
What can I add to the code to get it to open the folder if it exists or after it creates it.
You can use the function above. First call:
to create the path should it not exist.
Then use FileDialog to open the dialog window, like:
CreatePath Me!YourTextbox.Value
to create the path should it not exist.
Then use FileDialog to open the dialog window, like:
Private Sub txtTarget_DblClick(Cancel As Integer)
Dim Dialog As FileDialog
Dim Selected As Long
Set Dialog = FileDialog(msoFileDialogSaveAs)
With Dialog
.AllowMultiSelect = False
.InitialFileName = Nz(Me!txtTarget.Value)
.Title = "Name saved file"
Selected = .Show
If Selected <> 0 Then
Me!txtTarget.Value = .SelectedItems.Item(1)
End If
End With
End Sub
ASKER
https://www.experts-exchange.com/questions/29065725/How-create-a-folder-on-a-server-with-the-PK-as-the-folder-name.html