Automatically creating tables from spacing deliminated fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin R
    New Member
    • Nov 2011
    • 7

    Automatically creating tables from spacing deliminated fields

    I am trying to figure out how to write some sort of code that will go through the txt files in a folder and pull the data into fields plus the txt file name as well.

    For example I would like to pull all data after a : or ? plus the file name into a database and then go to the next row in the database and pull the data from the next txt file in that folder.

    This is an example layout of one of the files :
    Code:
    Computername______________________: ABCDEF001234AB
    Asset Tag: 1234567890
    Serial Number: MXL1310D1F
    HDD Info
    DiskSize = 160041885696
    Hard Drive Serial Number__________: WD-WCAV12345678
    Hard Drive Model Number___________: 00AABB-12A3B
    
     Carefully review the information and make corrections if needed
       *** Please fill in the following answers and save it ***
    
    HD encrypted ( Yes or No )? Yes
    Primary user (Last, First)? Doe, John
    Your Name? Name, My
    Last edited by NeoPa; Nov 16 '11, 11:55 PM. Reason: Showed info in post
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Based on your supplied example, I think you need to load the entire string into VBA, and then use string manipulation to try and read your info. You can load the file using code like this:
    Code:
    Public Function LoadFileToString(strFilePath As String) As String
        Dim intFileNumber As Integer
        Dim strContent As String
    
        
        'Get next free file number
            intFileNumber = FreeFile
    
        'Open the file
            Open strFilePath For Input As intFileNumber
        
        'Read to string
            strContent = Input$(LOF(intFileNumber), intFileNumber)
        
        'Close File
            Close intFileNumber
    
        'Return value
            LoadFileToString = strContent
    End Function
    You can then use the string manipulation tools provided by VBA such as instr, instrRev,Left,R ight,Mid,trim,s plit to try and work your way to the information you require.

    As to placing it into a table, I would suggest using a recordset. Example goes here:
    Code:
    Dim myRS as DAO.Recordset 'Requires reference set to Microsoft DAO 3.X library, x is version dependent
    'Open recordset
      set myRS=CurrentDB.Openrecordset("tbl_MyTable",dbopendynaset)
    'Add new record
      myRS.AddNew
      'Add information
      myRS!FieldName="Example" 'Replace FieldName with the name of your field
      'Update
      myRS.Update
    
    'Cleanup
    Set myRS=nothing
    This is just information intended to get you going. You will still require a moderate understanding of VBA to convert this to working code.

    Best of Luck.

    Comment

    • Kevin R
      New Member
      • Nov 2011
      • 7

      #3
      I think it would just be easier option would to see if I could pull the DiskSize, Hard Drive Serial Number, and Hard Drive Model Number through VBS then through a comma after each value when writing to the txt file.
      I have figured out how to pull the data for the first 3 lines in my text file (with the commas) and I can have popup prompts for the user to type in the last 3 lines. I just can't find anything on Google to run a straight VB script (not inside Access, or VB.Net, etc.) to pull the variables directly without having to use diskid32.exe and still have the hassel from the post above.

      Thank you for your help thus far!

      By the way the Mid function would work if only I could parse each line output from the diskid32 seperately and write the new variables to the txt file.

      Comment

      Working...