Question : Import data from text file to ms access table?

Hi:
I have the attach text file
Here is a sample of the data
NOMENCLATURE  
:
BATTERY ROTARY SWIT
STOCK NUMBER
:
5930143229030
UNIT OF ISSUE
:
EA
UNIT OF MEASUREMENT QUANTITY
:
1
QUANTITY REQUIRED
:
75
DESCRIPTION :  ROTARY SWITCH, BATTERY USE FOR VERY FAST
PATROL BOAT, POWER SUPPLY NETWORK 12VDC AND 24VDC.

Each block represent an item description, with the flowing attributes:

NOMENCLATURE
STOCK NUMBER
PART NUMBER
CAGE
UNIT OF ISSUE
UNIT OF MEASUREMENT CODE
UNIT OF MEASUREMENT QUANTITY
QUANTITY REQUIRED
DESCRIPTION
Some times the item got all of these attributes, and some times got some of them.
But always start with "NOMENCLATURE" and end with " DESCRIPTION"
Notice the "DESCRIPTION" always followed by data describe the item, while the other attributes are not.
I need to import these data to a MS Access table
Can I do so ?
please

Answer : Import data from text file to ms access table?

In line with hunt007's suggestion, please find below a code fragment that will correctly read a file created from your sample data and display messages for each identified field to be processed.

There are three places where such "processing" can occur, in part due to the awkward semantics of full-line headers for must fields, but not for DESCRIPTION, which starts on the same line...

I hope this gives you a starting point,
Happy coding!
(°v°)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
Sub ReadDataFile()
    
    Const DATAFILE = "d:\toto.txt"
    
    Dim strLine As String
    Dim strField As String
    Dim varValue As Variant
    
    Open DATAFILE For Input As #1
    varValue = Null
    Do Until EOF(1)
        Line Input #1, strLine
        Select Case Trim(strLine)
        Case "NOMENCLATURE", "STOCK NUMBER", "PART NUMBER", "CAGE", _
            "UNIT OF ISSUE", "UNIT OF MEASUREMENT CODE", _
            "UNIT OF MEASUREMENT QUANTITY", "QUANTITY REQUIRED"
                If Not IsNull(varValue) Then
                    MsgBox "Processing: " & strField & vbCrLf & varValue
                    varValue = Null
                End If
                strField = strLine
        Case Else
            If strLine Like "DESCRIPTION :*" Then
                If Not IsNull(varValue) Then
                    MsgBox "Processing: " & strField & vbCrLf & varValue
                    varValue = Null
                End If
                strField = "DESCRIPTION"
                varValue = Trim(Mid(strLine, 14))
            Else
                varValue = varValue + vbCrLf & strLine
            End If
        End Select
    Loop
    If Not IsNull(varValue) Then
        MsgBox "Processing: " & strField & vbCrLf & varValue
        varValue = Null
    End If
    Close #1
    
End Sub
Random Solutions  
 
programming4us programming4us