Results 1 to 7 of 7

Thread: splitting a column in alphabetic folders?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    3

    Question splitting a column in alphabetic folders?

    I have a tricky question (at least for me it's difficult).

    I have a number of rows like this:

    (Only one column)

    arthur
    augustine
    axl
    ceasar
    david
    erica
    elaine

    and so on (quite a few rows, for about 20000 in fact)

    i would like to put a file for each row beginning with "A" in its own folder, called "A", and so on, for each letter in the alphabet.

    In this case: 3 files in "A"-folder, one file in "C", and one in "D", and two in "E".

    This seems very difficult. I have no idea how to do this "split"?

    Could someone with more experience give me a VBA-example of how i would do this (i understand that it would have to be a loop going through all the rows, but that's about all i know)...

    Thanks for any help,
    Goncha.

  2. #2
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Re: splitting a column in alphabetic folders?

    im able to create upto directories...
    im not getting how to create files...
    can any body give me an example of creating files..
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

  3. #3
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Re: splitting a column in alphabetic folders?

    well...goncha

    finally I got it..i dont know wether the process that im fallowing is right or not,
    but im acheving the target...
    chk the attachment once.
    Attached Files Attached Files
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    3

    Re: splitting a column in alphabetic folders?

    Hello!!

    Thank you for trying to help me, nagasrikanth!

    The file you attached contains only a database. Did you forget to add something?

    G.

  5. #5
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Re: splitting a column in alphabetic folders?

    Nothing else is required...
    just chk out the database and in the forms open the form,and click the button...

    it will results u r folders and files in "C:\" Drive..
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    3

    Re: splitting a column in alphabetic folders?

    I can not read the database direct from where i am.
    Could you please show me the code direct here in the forum instead, or send it to me as a message?

    Many thanks in advance for your time,
    G.

  7. #7
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Re: splitting a column in alphabetic folders?

    okay...then...here is the code...
    first place u r data in a table named "table1" and then run this code by placing it in a form
    VB Code:
    1. Option Compare Database
    2. Option Explicit
    3. Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpPathName As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
    4. Private Type SECURITY_ATTRIBUTES
    5.     nLength As Long
    6.     lpSecurityDescriptor As Long
    7.     bInheritHandle As Long
    8. End Type
    9.  
    10.  
    11. Private Sub Command0_Click()
    12.     Dim Security As SECURITY_ATTRIBUTES
    13.     Dim prevletter
    14.     Dim fstletter
    15.     Dim lngHandle As Long
    16.     Dim rst As Recordset
    17.     Dim fs As New FileSystemObject
    18.     Dim flname
    19.     Dim fl
    20.     Set rst = CurrentDb.OpenRecordset("table1")
    21.     If Not rst.RecordCount = 0 Then
    22.         rst.MoveFirst
    23.         While Not rst.EOF
    24.         fstletter = Left(rst(0), 1)
    25.         If Not prevletter = fstletter Then
    26.             CreateDirectory "C:\" & fstletter, Security
    27.             prevletter = fstletter
    28.         End If
    29.         flname = fs.BuildPath("c:\" & fstletter, rst(0) & ".txt")
    30.         Set fl = fs.CreateTextFile(flname, True)
    31.         rst.MoveNext
    32.         Wend
    33.     End If
    34.  
    35.  
    36. End Sub
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

Posting Permissions

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



Click Here to Expand Forum to Full Width