create a new folder using Access?-VBForums
Results 1 to 6 of 6

Thread: create a new folder using Access?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    3

    create a new folder using Access?

    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.

  2. #2
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: create a new folder using Access?

    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:
    1. Public Sub CreateNewFolder(folderName As String)
    2.     Dim fso As FileSystemObject
    3.     Set fso = New FileSystemObject
    4.    
    5.     Call fso.CreateFolder(folderName)
    6. 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:
    1. Private Sub Command0_Click()
    2.     Call Module1.CreateNewFolder("c:\-- TestFolder --")
    3. 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.
    Last edited by Optional; Mar 26th, 2010 at 10:04 AM.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    36,799

    Re: create a new folder using Access?

    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    3

    Re: create a new folder using Access?

    [QUOTE=Optional;3762551]

    Select your Database and add a code module.

    Write the following public method:
    VB Code:
    1. Public Sub CreateNewFolder(folderName As String)
    2.     Dim fso As FileSystemObject
    3.     Set fso = New FileSystemObject
    4.    
    5.     Call fso.CreateFolder(folderName)
    6. 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..

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    3

    Re: create a new folder using Access?

    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

  6. #6
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: create a new folder using Access?

    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.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.