[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Parse text and send to database

Posted on 2003-12-11
3
Medium Priority
?
170 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 500 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses

650 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