• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

Parse text and send to database

I have never programmed with VB before.  I have never programmed.  I have a need to parse data ina text document and send certain results into a database for analysis.

The data looks like this:

Clinic:   WLA-ALLERGY F/U
Patients: 1     Orders: 1
In Sort Groups: WLA-CLINIC
                WLA ALLERGY
 
Clinic:   WLA-DERM GENERAL
Patients: 3     Orders: 5
In Sort Groups: WLA-CLINIC
                WLA DERM
 
Clinic:   WLA-H&NS (HEAD & NECK SURGERY)
Patients: 1     Orders: 1
In Sort Groups: WLA-CLINIC


I want to parse the name of the clinic and the number of orders.  Then put the data into a database.  I do know how to build an access db, just not about writing access modules.

Where do I start???

--Pharmacist
0
pharmacist
Asked:
pharmacist
1 Solution
 
vinnyd79Commented:
' add a reference to Microsoft ActiveX Data Objects Library:

Private Sub Command1_Click()
Dim DataBase As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
DataBase = "C:\MyDataBase.mdb"

' open Database Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & DataBase & "'"
cn.CursorLocation = adUseClient
cn.Open

' open recordset
Set rs = New ADODB.Recordset
rs.Open "Select * From [YourDBTableName]", cn, adOpenKeyset, adLockOptimistic

' read Text File and add to DB
Dim TextFile As String, Ln As String, arrLn() As String
Dim ff As Integer
Dim Clinic As String, Orders As Integer

TextFile = "C:\MyFile.txt"

ff = FreeFile
Open TextFile For Input As #ff
Do Until EOF(ff)
' read line from file
Line Input #ff, Ln
' check to see if Clinic is on the Line
If InStr(Ln, "Clinic:") > 0 Then
    ' split line into array to get Clinic name
    arrLn = Split(Ln, "Clinic:")
    Clinic = arrLn(1)
    ' get next line (should have the Orders on this line)
    Line Input #ff, Ln
    ' split line into array to get Order amount
        arrLn = Split(Ln, "Orders:")
        Orders = arrLn(1)

' add new record to Table
rs.AddNew
' add to Field named Clinic
rs.Fields("Clinic").Value = Clinic
' add to Field named Orders
rs.Fields("Orders").Value = Orders
rs.Update
End If
' get next line
Loop

' close recordset
rs.Close
Set rs = Nothing

' close connection
cn.Close
Set cn = Nothing
End Sub
0
 
planoczCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
No response from pharmacist from 12/11/2003 comment
Award points to vinnyd79 is recommend.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

planocz
EE Cleanup Volunteer
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now