Results 1 to 11 of 11
  1. #1
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150

    Create A Folder With Textbox Value

    Hi Guys



    Code:
    Dim strDir As String    strDir = "D:\Timesheets " & Me.Text11
        
        If Dir(strDir, vbDirectory) = "" Then
            MkDir strDir
        Else
            MsgBox "Directory exists."
        End If

    Above is the code im using to create a folder in access, however i want to create a folder based on a textbox input value. (Me.Text11), above is not working. appreciate your help.

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    So if Text11= abc, are you expecting to get D:\Timesheets abc or D:\Timesheets\abc
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150
    HI Ridders

    if text11=abc

    im expecting the out put as D:\Timesheets - abc\

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What does 'not working' mean - error message, wrong result, nothing happens?

    The concatenated string is missing hyphen and following space.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    There's nothing wrong with the code apart from the missing '- ' which June mentioned
    This works for me on a button click event

    Code:
    Private Sub cmdMakeFolder_Click()
    
        Dim strDir As String
        strDir = "D:\Timesheets - " & Me.Text11
        
        If Dir(strDir, vbDirectory) = "" Then
            MkDir strDir
        Else
            MsgBox "Directory exists."
        End If
    End Sub
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150
    Hi

    when i run the above code, i get run time error 76. path not found.

  7. #7
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    It could be that
    a) the drive doesn't exist or isn't mapped
    b) the control contains characters or words that are not allowed in folder/file names
    c) the event you're using is not appropriate for this (you don't reveal what event it is)
    If you are sure the drive letter is available on the pc that generates the error, it might help if you provide an example of what's in the control when that error is raised.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I ran code testing for condition a. Don't get error, just empty string.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Join Date
    Apr 2017
    Posts
    1,680
    Debug the code!

    Open the OnClick event of button;
    After row where variables are declared (Dim ...), add On Error statement to avoid the event code to be stopped when an error occurs;
    Set breakpoint on
    Code:
        strDir = "D:\Timesheets - " & Me.Text11
    Run the event;
    The event code is stopped and opened. Activate Watch window at bottom of debug window, when it is missing;
    Select "strDir" from code and right-click on it to add variable to Watch window. Or type varieble/expression directly into Watch window. Press F8 - the active row is executed, the code stops at next row, and the value the variable strDir got is displayed in Watch window;
    Repeat this with other rows, adding variables/expressions into Watch window [Dir(strDir, vbDirectory)] to check what the code actually does until you get the error message;
    Based on values returned in Watch window, you can locate the problem which causes the error.

    (Without On Error statement, when the error occurs, the execution of code is stopped, and all watches you set are not defined anymore. So you can't chek them anymore. Of-course you can always write them down when debuging.)

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    I just tried micron's suggested conditions a & b
    a) Non existent drive
    b) illegal characters such as ? and / in the textbox
    In each case, I got error 76 - path not found

    I didn't bother testing condtion c

    As Arvil has already suggested, add error checking / handling to your code
    The following may be helpful:

    Code:
    Private Sub Command2_Click()
    
    On Error GoTo Err_Handler
    
    
        Dim strDir As String
        strDir = "D\Timesheets - " & Me.Text11
        
        If Dir(strDir, vbDirectory) = "" Then
            MkDir strDir
        Else
            MsgBox "Directory exists."
        End If
        
    Exit_Handler:
        Exit Sub
    
    
    Err_Handler:
        If Err = 76 Then
            MsgBox "A directory cannot be created at :" & vbCrLf & " - " & strDir
        Else
            MsgBox "Error " & Err.Number & " in Command2_Click procedure : " & Err.Description
        End If
        Resume Exit_Handler
    
    
    End Sub
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150
    Hi Guys

    Code:
    Private Sub cmdMakeFolder_Click()
    
        Dim strDir As String
        strDir = "D:\Timesheets - " & Me.Text11
        
        If Dir(strDir, vbDirectory) = "" Then
            MkDir strDir
        Else
            MsgBox "Directory exists."
        End If
    End Sub
    above code is working.

    due a missing operator error, i got the error 76
    Thanks alot for your help guys.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Create a folder into a network location
    By charly.csh in forum Access
    Replies: 7
    Last Post: 12-04-2015, 10:02 AM
  2. mkdir basic help - create folder for each new record
    By hstroud38 in forum Programming
    Replies: 6
    Last Post: 03-28-2012, 04:30 PM
  3. VBA to create PDF and folder if doesn't exist!
    By crxftw in forum Programming
    Replies: 2
    Last Post: 08-08-2011, 08:53 AM
  4. create On Click to go to specific server folder
    By airhud86 in forum Programming
    Replies: 1
    Last Post: 01-05-2010, 12:45 PM
  5. Replies: 0
    Last Post: 12-16-2009, 09:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums