Create a folder for every new record

rleistra

New member
Local time
Today, 13:27
Joined
Jun 22, 2013
Messages
5
Hi everyone,

I want Access to create a folder for every new record that is added to the database, and the folder name has to be a value of that record.

To make it clear:

s3.postimg.org/n66zcjwcz/access.png

The foldername has to be "123456789" for the first record.

Can anyone help me with a module to do this?

I've been looking everywhere but without a result..
 
In the Code Module behind the Form:
Code:
Sub MakeFolder(strPath As String)
    If Dir(strPath, vbDirectory) > vbNullString Then
        Exit Sub
    End If
    MkDir strPath
End Sub

Then, replacing c:\FullPath\ with the actual Full Path and TargetControl with the name of the Textbox that holds the name of the Folder being created
Code:
Private Sub cmdMakeFolder_Click()
 MakeFolder "C:\FullPath\" & Me.TargetControl
End Sub

So if TargetControl = 123456

the code would create a Folder:

c:\FullPath\123456

I've shown the Folder being created using a Command Button named cmdMakeFolder, but the same code could be placed in the TargetControl_AfterUpdate event, or in the Form_BeforeUpdate event, as well, depending on your needs.

Linq ;0)>
 
I don't use a form to insert a new record.

The database gets it's data from a form I've created in Visual Basic Express.

I type in the data (Name, lastname etc.) press the "save" button, and then a new record is created in the database.
 
...I don't use a form to insert a new record...The database gets it's data from a form I've created in Visual Basic Express...

Then why are you asking a question about how to perform an operation, using Visual Basic Express, in an MS Access forum? Using MS Access as a Back End does not make this an Access problem.

Linq ;0)>
 
Excuse me for wasting your time then.

I just tought that if I'd let Access create a folder for every new record it gets, my problem would be solved.
 
No real waste of time, but if your Front End is through VBE that's where you need to do this, I would think.

Linq ;0)>
 
In the Code Module behind the Form:
Code:
Sub MakeFolder(strPath As String)
Code:
[B]  If Dir(strPath, vbDirectory) > vbNullString Then[/B]
[B]      Exit Sub[/B]
[B]  End If[/B]
[B]  MkDir strPath[/B]
[B]End Sub[/B]

Then, replacing c:\FullPath\ with the actual Full Path and TargetControl with the name of the Textbox that holds the name of the Folder being created
Code:
Private Sub cmdMakeFolder_Click()
Code:
[B]MakeFolder "C:\FullPath\" & Me.TargetControl[/B]
[B]End Sub[/B]

So if TargetControl = 123456

the code would create a Folder:

c:\FullPath\123456

I've shown the Folder being created using a Command Button named cmdMakeFolder, but the same code could be placed in the TargetControl_AfterUpdate event, or in the Form_BeforeUpdate event, as well, depending on your needs.

Linq ;0)>

I am trying to use this code, but am receiving an error:

Run-time error '2465':
Microsoft Access can't find the field '|1' referred to in your expression.

Here is what my code looks like:

Private Sub Form_AfterUpdate()
MakeFolder "R:\My Location\" & Me.[ComplaintsQuery]![NumberSort]
End Sub

I'm not sure what needs to go in the "Me." and "TargetControl", what I currently have for TargetControl is a field called NumberSort from a query called ComplaintsQuery.

I'm new to this so any help would be appreciated!
 

Users who are viewing this thread

Back
Top Bottom