Solved

Parse text and send to database

Posted on 2003-12-11
3
158 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 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