Results 1 to 15 of 15
  1. #1
    np1111 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    10

    New directory with the name from field

    Hi,


    i have a little problem with access. I would like to create a macro which will make a directory with the name from the field from table. I have the filed name "CECHA" but
    mkdir "D:\DIRECTORY\CECHA"

    it creates a directory with the name "CECHA" but not a value of the field CECHA.

    Please help me with it.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    mkdir "D:\DIRECTORY\" & [CECHA]

  3. #3
    np1111 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    10
    Ok it works fine, but i have another problem with this command.

    CECHA is the field that have a values looks like 854136asdg.5748asd
    how can i make a directory with mkdir but with the name from the field CECHA till dot?
    CECHA - 854136asdg.5748asd
    Directory - D:/DIRECTORY/854136asdg/

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    With the following in a standard module named basFunction:
    Code:
    Function LastParam(inString As String) As String
    '-- Return the SubString before the last "." in InString
    LastParam = left(inString, InStrRev(inString, ".") - 1)
    End Function
    ...you could then use:
    mkdir "D:\DIRECTORY\" & LastParam([CECHA])

  5. #5
    np1111 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    10
    I think i am doing something wrong because it doesn't work
    Code:
    Private Sub Polecenie83_Click()
    Function LastParam(inString As String) As String
    '-- Return the SubString before the last "." in InString
    LastParam = Left(inString, InStrRev(inString, ".") - 1)
    End Function
    
    MkDir "D:\DIRECTORY\" & LastParam([CECHA])
    End Sub

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    First, you can not put a function inside of a Sub. Next, I said to put the function in a standard module named basFunction, not in the code for your form.

  7. #7
    np1111 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    10
    I don't know how to do that.
    I made something like that:
    HTML Code:
    Option Compare Database
    Function LastParam(inString As String) As String
    '-- Return the SubString before the last "." in InString
    LastParam = Left(inString, InStrRev(inString, ".") - 1)
    End Function
    
    Private Sub Polecenie83_Click()
    MkDir "D:\DIRECTORY\" & LastParam([CECHA])
    End Sub
    but it doesn't work

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Your standard module named basFunction should only look like:
    Code:
    Option Compare Database
    Option Explicit
     
    Function LastParam(inString As String) As String
    '-- Return the SubString before the last "." in InString
       LastParam = left(inString, InStrRev(inString, ".") - 1)
    End Function
    Then in your FORM, your Click code should look like:
    Code:
    Private Sub Polecenie83_Click()
       MkDir "D:\DIRECTORY\" & LastParam([CECHA])
    End Sub

  9. #9
    np1111 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    10
    Thanks - it works.

    I have another problem. Only part of the CECHA have a "." in the name.
    I must do something to check it.

    HTML Code:
    Option Compare Database
    
    
    Function LastParam(inString As String) As String
    '-- Return the SubString before the last "." in InString
    
    
    LastParam = Left(inString, InStrRev(inString, ".") - 1)
    End Function
    Function LeftCheck(inString As String) As String
    LeftCheck = InStrRev(inStirng, ".")
    End Function
    
    
    Private Sub Polecenie83_Click()
    
            If LeftCheck([CECHA_1]) = 0 Then
            MkDir "D:\DIRECTORY\" & [CECHA_1]
            Else
            MkDir "D:\DIRECTORY\" & LastParam([CECHA_1])
            End If
          
    
    
    End Sub
    Why it doesn't work?

  10. #10
    np1111 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    10
    Ok. I solved this.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I would have just changed the Function:
    Code:
    Function LastParam(inString As String) As String
    '-- Return the SubString before the last "." in InString
    If InStr(inString,".") Then
       LastParam = left(inString, InStrRev(inString, ".") - 1)
    Else
       '-- No period in the string, just return the string
       LastParam = inString
    End If
    End Function
    Are you ready to follow the link in my sig and mark this thread as Solved?

  12. #12
    np1111 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    10
    Yes,
    but i have one more question.
    I want to open a directory that this function create.
    When i am on the one of the CECHA - i would like to open this directory (of that CECHA).
    I have function:
    HTML Code:
    Private Sub OTWORZ_FOLDER_Click()
    
    If InStr([CECHA_1], ".") > 0 Then
            KATALOG = Dir("P:\OPRZYRZADOWANIE_KJWP\" & [NAZWA_1], vbDirectory)
            Shell ("EXPLORER.EXE P:\OPRZYRZADOWANIE_KJWP\&[NAZWA_1]\&LastParam([CECHA_1])")
    Else
            KATALOG = Dir("P:\OPRZYRZADOWANIE_KJWP\" & [NAZWA_1], vbDirectory)
            Shell ("EXPLORER.EXE P:\OPRZYRZADOWANIE_KJWP\ & [NAZWA_1] \ & [CECHA_1]")
    End If
    End Sub
    But it isn't working. Help

  13. #13
    np1111 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    10
    Ok. SOLVED.

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Great! Glad we could assist.

  15. #15
    np1111 is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Posts
    10
    Thanks a lot!

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

Similar Threads

  1. Replies: 3
    Last Post: 08-25-2010, 09:03 AM
  2. Use form List Box to query Active Directory
    By grafiksinc in forum Forms
    Replies: 4
    Last Post: 12-02-2009, 11:56 PM
  3. Replies: 1
    Last Post: 08-14-2009, 03:53 AM
  4. Parse a File from a Directory and write data to table
    By galahad in forum Database Design
    Replies: 0
    Last Post: 04-23-2009, 08:38 AM
  5. Replies: 1
    Last Post: 02-26-2009, 11:31 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