Solved

Parse text and send to database

Posted on 2003-12-11
3
159 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Updates not working for MS Windows 7 12 194
how to know if my Checkbox is True in VB6.0? 9 65
Child Form in front 4 56
VB6 common control 6 sp6 object library not registerd 3 45
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…
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…
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…
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…

749 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