Solved

Parse text and send to database

Posted on 2003-12-11
3
148 Views
Last Modified: 2010-05-03
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
Comment
Question by:pharmacist
3 Comments
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 125 total points
ID: 9921069
' 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
 
LVL 27

Expert Comment

by:planocz
ID: 10270486
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now