Please Help On Folder Creation

extreme

Registered User.
Local time
Today, 21:05
Joined
Sep 27, 2004
Messages
51
Please help I want to create a new folder on my harddrive when I click on a button I have been trying to sort this out for a long time now but with no joy.


Thanks again This site as helped me alot keep up the good work
 
Hi

I used this site for help - I had the same problem as you a little while back

http://en.allexperts.com/q/Visual-Basic-1048/VB-6-3-path.htm

Thanks For the reply very quick

Tried this didnt work for me I need a code so when I put a site name in the form and then clicks a button to add new site it will create a folder in c:\data\the name of thenew site folder here

then go to another form

Can this be done.
 
I tested this on a db here and it successfully created a new directory.

You can then use the docmd.openform syntax to open a new form

Code:
Private Sub Command1_Click()
Dim lngRetval As Long
Dim strName As String, strFile As String, strFileName As String


strName = Me.Text12 ' then name of the text box that holds your site
strFile = "c:\data\" ' default file location
strFileName = strFile & strName ' the full directory name

If Dir(strFileName, vbDirectory) <> "" Then
   ' Directory exists, insert your file output code here
Else
   ' Directory doesn't exist
   ' Prompt user if he wants it to be created
   lngRetval = MsgBox("Create path?", vbYesNo, "Path doesn't exist")
   If lngRetval = 6 Then
       ' User asked to create dir, so create it.
       ' Well, the nested directory doesn't exist, but need
       ' to check if the vbtemp exists to avoid similar error
       If Dir(strFile, vbDirectory) <> "" Then
           ' Just create the sub-directory
           MkDir (strFileName)
       Else
           ' Create main and then sub-dir
           MkDir (strFile)
           MkDir (strFileName)
       End If
       ' Check if it got created
       If Dir(strFileName, vbDirectory) <> "" Then
           ' Let user know it was success
           MsgBox ("Path created succesfully.")
       Else
           ' Let user know it was failure
           MsgBox ("Error creating path.")
       End If
   Else
       ' User asked not to create dir
       MsgBox ("Path was not created.")
   End If
End If
End Sub
 
Just to clarify, I did not have a directory C:\Data befor I ran this command. I entered "Test" into the control (name = text12) on my form. When I clicked the command button, I ended up with the following directory C:\Data\Test
 
I tested this on a db here and it successfully created a new directory.

You can then use the docmd.openform syntax to open a new form

Code:
Private Sub Command1_Click()
Dim lngRetval As Long
Dim strName As String, strFile As String, strFileName As String


strName = Me.Text12 ' then name of the text box that holds your site
strFile = "c:\data\" ' default file location
strFileName = strFile & strName ' the full directory name

If Dir(strFileName, vbDirectory) <> "" Then
   ' Directory exists, insert your file output code here
Else
   ' Directory doesn't exist
   ' Prompt user if he wants it to be created
   lngRetval = MsgBox("Create path?", vbYesNo, "Path doesn't exist")
   If lngRetval = 6 Then
       ' User asked to create dir, so create it.
       ' Well, the nested directory doesn't exist, but need
       ' to check if the vbtemp exists to avoid similar error
       If Dir(strFile, vbDirectory) <> "" Then
           ' Just create the sub-directory
           MkDir (strFileName)
       Else
           ' Create main and then sub-dir
           MkDir (strFile)
           MkDir (strFileName)
       End If
       ' Check if it got created
       If Dir(strFileName, vbDirectory) <> "" Then
           ' Let user know it was success
           MsgBox ("Path created succesfully.")
       Else
           ' Let user know it was failure
           MsgBox ("Error creating path.")
       End If
   Else
       ' User asked not to create dir
       MsgBox ("Path was not created.")
   End If
End If
End Sub

THANKS WORKS PERFECT NICE ONE

I hope you dont mind me asking I am a noobie but do I add docmd.openform syntax to this code before the End Sub
 
Howzit

No problem at all, we all started as noobies. Yes before the end sub
 
Howzit

No problem at all, we all started as noobies. Yes before the end sub

Sorry for being a pain but could you tell me if this code is ok to open a new form in the code you provided

thank you

Private Sub Command8_Click()
Dim lngRetval As Long
Dim strName As String, strFile As String, strFileName As String


strName = Me.SiteName ' then name of the text box that holds your site
strFile = "c:\AsbestosSurveyPro\data\" ' default file location
strFileName = strFile & strName ' the full directory name

If Dir(strFileName, vbDirectory) <> "" Then
' Directory exists, insert your file output code here
Else
' Directory doesn't exist
' Prompt user if he wants it to be created
lngRetval = MsgBox("Create path?", vbYesNo, "Path doesn't exist")
If lngRetval = 6 Then
' User asked to create dir, so create it.
' Well, the nested directory doesn't exist, but need
' to check if the vbtemp exists to avoid similar error
If Dir(strFile, vbDirectory) <> "" Then
' Just create the sub-directory
MkDir (strFileName)
Else
' Create main and then sub-dir
MkDir (strFile)
MkDir (strFileName)
End If
' Check if it got created
If Dir(strFileName, vbDirectory) <> "" Then
' Let user know it was success
MsgBox ("Path created succesfully.")
Else
' Let user know it was failure
MsgBox ("Error creating path.")
End If
Else
' User asked not to create dir
MsgBox ("Path was not created.")
End If
End If

Dim strDocName As String

strDocName = "Survey"
DoCmd.OpenForm strDocName, , , , acFormAdd
End Sub
 
Howzit

That looks about right. It will open the form Survey, in a new record
 

Users who are viewing this thread

Back
Top Bottom