hi,
Can anyone help me create a button in MS-Access03 form that would allow me create a folder name using one of the field value on that form?
Is there a code to create new folder...?
Thanks.
Printable View
hi,
Can anyone help me create a button in MS-Access03 form that would allow me create a folder name using one of the field value on that form?
Is there a code to create new folder...?
Thanks.
In MS Access, open the Macro Page.
Tools >> Macro >> Visual Basic Editor
Ones on the Visual Basic Editor, add a reference to the Microsoft Scripting Runtime.
Tools >> References... , in dialog tick Microsoft Scripting runtime
Select your Database and add a code module.
Write the following public method:
VB Code:
Public Sub CreateNewFolder(folderName As String) Dim fso As FileSystemObject Set fso = New FileSystemObject Call fso.CreateFolder(folderName) End Sub
Go back to your form with the button on it.
Double-click your button and select the event tab.
go to the "On Click" event and select the [Event Procedure] option from the dropdown.
Then click the "..." button and write the following in your event code:
VB Code:
Private Sub Command0_Click() Call Module1.CreateNewFolder("c:\-- TestFolder --") End Sub
Go back to your Form and run it.
click the button and the folder will be created, assuming you have a C:\ drive you can write to.
The above simply shows you a small sample and proof of concept on how to achieve what you need.
Adding error handling and changing the code to fit your needs will be up to you.
Note: You don't need Module1. when calling the method as the method name is simply enough. However, it will ensure you are definetly calling the method of that Module and not another component or object.
Have Fun.
Thread moved to 'Office Development/VBA' forum... note that while it certainly isn't made clear, the "VB Editor" in Office programs is actually VBA rather than VB, so the 'VB6' forum is not really apt
[QUOTE=Optional;3762551]
Select your Database and add a code module.
Write the following public method:
VB Code:
Public Sub CreateNewFolder(folderName As String) Dim fso As FileSystemObject Set fso = New FileSystemObject Call fso.CreateFolder(folderName) End Sub
QUOTE]
Thanks for quick reponse. I got rest of part but the aboe section..I do not know where and how you do this in public method? I'm sorry i have no knowledge of for codding..
Code:Call Module1.CreateNewFolder("c:\-- TestFolder --")End Sub
Alright. I got that to work partially. It creates folder with whatever I type after C:\...
I need something that pick up field value within that form and use that as name of folder...is it possible??
Thanks
if you need to access the value from fields you can access the controls and values from the code.
A TextBox for exmaple has a Texbox.Text property you can access.
If you have difficulties in writing the code and accessing values from some of the controls, I'm afraid you are going to have to read up on VBA for MSAccess.
I didn't look yet on the forums but I'm sure there will be a lot of info on VBA on this forum.