Hi! I hope someone can help or point me in the right direction here. I am working on a vb app and I need to import a text file into the program(database) and I don’t have a clue as to how to do this. My app has a database named layouts that contains 4 fields one of which is a part number field. I need to match that part number field up to the part number field in a text file (the text file is generated by a proprietary system and there’s no other way of getting the info out.) and only display those matching records. (If theres a part number in the layouts database, I need only the matching records from the text file.)
The text file is a +-sign delimited file and the user needs to be able to press an Update button and have this file imported into the program and displayed in a table-like fashion or grid. The info in the text file is read only and does not need to be edited.
I am a vb newbie and really have no idea where to even begin on this. ALL help is VERY much appreciated! Thank You!
Kris
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Databases (VB 6)
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Databases (VB 6)
- This topic has 21 replies, 5 voices, and was last updated 22 years, 11 months ago.
AuthorTopicWSmarinthal
AskWoody LoungerJune 18, 2002 at 1:36 pm #372441Viewing 1 reply threadAuthorReplies-
WScharlotte
AskWoody Lounger -
WSmarinthal
AskWoody Lounger -
WBell
AskWoody_MVPJune 20, 2002 at 3:32 pm #596056You might find this thread on importing an Excel worksheet into Access using VB of interest. It presumes you have a copy of Access so you can use the Transfer command, but would save you hours of grief in trying to write an import process that would convert your text to an Access table.
-
WSmarinthal
AskWoody Lounger -
WBell
AskWoody_MVP
-
-
-
-
-
WSSammyB
AskWoody LoungerJune 20, 2002 at 11:37 am #595989Since it is just a text file, I would not use OLE to read it. I would use an Open statement, Line Input statements, and the Split function.
To give more information than that, I would need to know more about the text file, especially what you mean by +- sign deliminated. Can you put several lines into Word, change any words/data that are proprietary, and attach it to a reply to this post? Thanks! –Sam
-
WSmarinthal
AskWoody Lounger -
WSHansV
AskWoody LoungerJune 21, 2002 at 8:13 am #596194(I see no attachment to your post)
To summarize what Sam and Wendell have been telling you:
- If you users have Access, you can use Automation to let Access do things for you from within your VB6 application. An advantage of this is that Access can import a text file into a table using the DoCmd.TransferText method; you don’t have to read the text file line by line.
- If your users don’t have Access or if if using Access (even “under cover”) is not an option:
- Use the Open instruction to open the text file, and read it line by line using the Input or Line Input instructions.
- Use ADODB (or DAO) to open the appropriate table in the database as a recordset, append a record for each line read from the text file, and write the values to the fields of the record.
It’s more work than using Access, but it shouldn’t be too hard. Look up “Open statement”, “Input statement” and “Line input statement” in the help index to see how you can open and read a text file. Look up “AddNew method” to see how you can add a record to a recordset.
[/list] -
WSSammyB
AskWoody Lounger -
WSmarinthal
AskWoody Lounger -
WSSammyB
AskWoody LoungerJune 21, 2002 at 12:48 pm #596225That is VERY UGLY. Do they really have variable length fields, missing months, missing dollar signs, etc? What do the + signs mean? You originally said it was plus/minus sign deliminated? Do they throw in minus signs also? Are the numbers ever negative?
Except for the missing month, it seems that, if you ignore $ signs and plus signs, then the file is space deliminated. Is this true? –Sam
-
WSmarinthal
AskWoody LoungerJune 21, 2002 at 4:12 pm #596283Yep, sure is ugly! The fields are fixed length and I don’t know why the + signs show up several spaces after unless the program thats exporting the data is setup to do that. (No minus signs – I misinterpreted the file wrong, my mistake.)There can be no negative numbers in any of the fields.
I have no clue how to parse the fields out either!Kris
-
WSSammyB
AskWoody LoungerJune 21, 2002 at 4:33 pm #596287 -
WSmarinthal
AskWoody LoungerJune 21, 2002 at 7:07 pm #596307Ok, now I’m slightly confused. Anyway, I could not get Excel to import the data as fixed length, I had to change it to delimited using the plus sign as the delimiter. If you import as fixed length it seperates all the plus signs into their own columns. (Attached is the spreadsheet)
Kris
-
WSSammyB
AskWoody LoungerJune 21, 2002 at 7:30 pm #596315> it seperates all the plus signs into their own columns
But, you can double-click on a line to remove that breakpoint. Notice that with your sample data the numbers seem to be shifted to the left on each line. I assumed that you had a larger file that you could experiment with. Before you try the import again, edit the file with Notepad and replace all of the plus-signs with blanks. We need a firm input specification before we can write code. –Sam
-
WSmarinthal
AskWoody Lounger -
WSHansV
AskWoody LoungerJune 24, 2002 at 2:18 pm #596624Maybe this code can serve as starting point. It uses the originally attached text file with “+” as separator. And it’s written for DAO, because that’s what I’m most familiar with, but modifying it for ADO shoudn’t be difficult. As it stands, it needs a reference to the DAO object library.
To make it work better, you need to add data cleaning. For instance, there are some very strange dates in the text file.
Private Sub Command1_Click()
Dim strLine As String
Dim strFields
Dim i As Integer
Dim wsp As DAO.Workspace
Dim dbs As DAO.Database
Dim rst As DAO.RecordsetOn Error GoTo Err_Command1_Click
Set wsp = DAO.DBEngine.Workspaces(0)
Set dbs = wsp.OpenDatabase(“C:MyProjectMyDatabase.mdb”)
Set rst = dbs.OpenRecordset(“tblMyTable”)Open “C:MyProjectMyText.txt” For Input As #1
‘ Get field names
Line Input #1, strLine
strFields = Split(strLine, “+”)
‘ Get records
Do While Not EOF(1)
Line Input #1, strLine
strFields = Split(strLine, “+”)
‘ Add record to table
rst.AddNew
For i = LBound(strFields) To UBound(strFields)
rst.Fields(i) = strFields(i)
Next i
rst.Update
LoopExit_Command1_Click:
‘ Clean up
On Error Resume Next
Close #1
rst.Close
Set rst = Nothing
Set dbs = Nothing
Set wsp = Nothing
Erase strFields
Exit SubErr_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click
End Sub -
WSSammyB
AskWoody LoungerJune 26, 2002 at 11:37 am #597117I finally found the time to put some code together. I used the Add In | Visual Data Manager to create an Access database with one table with your 8 fields. Then I used the Project | Add Form | VB Data Form Wizard to create a form for that table and fields (remember to place the fields in the same order as in the text file) without any controls. This creates a form with an array of text boxes, txtFields, which are bound to your database via an ADO control, datPrimaryRS. I added a button to the form to read your file and replaced all of the code that the wizard generated with the code below. It follows the scheme of parsing on the plus sign. Note that I did no error checking. From the looks of your file, you will want to add alot of that. HTH –Sam
Option Explicit Private Sub Command1_Click() Dim s As String Dim v As Variant Dim i As Integer Open App.Path & "New.txt" For Input As #1 Line Input #1, s ' Skip header Do Line Input #1, s s = Replace(s, "$", " ") ' Pitch the dollar signs v = Split(s, "+") ' Parse with plus sign deliminator datPrimaryRS.Recordset.AddNew For i = 0 To txtFields.Count - 1 txtFields(i) = Trim(v(i)) Next i datPrimaryRS.Recordset.Update Loop Until EOF(1) Close #1 End Sub
-
WSmarinthal
AskWoody Lounger -
WSSammyB
AskWoody Lounger -
WSmarinthal
AskWoody Lounger
-
-
-
-
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Login screen icon
by
CWBillow
52 minutes ago -
AI coming to everything
by
Susan Bradley
2 hours, 29 minutes ago -
Mozilla : Pocket shuts down July 8, 2025, Fakespot shuts down on July 1, 2025
by
Alex5723
4 hours, 40 minutes ago -
No Screen TurnOff???
by
CWBillow
5 hours, 1 minute ago -
Identify a dynamic range to then be used in another formula
by
BigDaddy07
5 hours, 34 minutes ago -
InfoStealer Malware Data Breach Exposed 184 Million Logins and Passwords
by
Alex5723
17 hours, 11 minutes ago -
How well does your browser block trackers?
by
n0ads
3 hours, 28 minutes ago -
You can’t handle me
by
Susan Bradley
7 hours, 53 minutes ago -
Chrome Can Now Change Your Weak Passwords for You
by
Alex5723
2 hours, 57 minutes ago -
Microsoft: Over 394,000 Windows PCs infected by Lumma malware, affects Chrome..
by
Alex5723
1 day, 4 hours ago -
Signal vs Microsoft’s Recall ; By Default, Signal Doesn’t Recall
by
Alex5723
8 hours, 3 minutes ago -
Internet Archive : This is where all of The Internet is stored
by
Alex5723
1 day, 4 hours ago -
iPhone 7 Plus and the iPhone 8 on Vantage list
by
Alex5723
1 day, 5 hours ago -
Lumma malware takedown
by
EyesOnWindows
17 hours, 18 minutes ago -
“kill switches” found in Chinese made power inverters
by
Alex5723
1 day, 13 hours ago -
Windows 11 – InControl vs pausing Windows updates
by
Kathy Stevens
1 day, 13 hours ago -
Meet Gemini in Chrome
by
Alex5723
1 day, 17 hours ago -
DuckDuckGo’s Duck.ai added GPT-4o mini
by
Alex5723
1 day, 17 hours ago -
Trump signs Take It Down Act
by
Alex5723
2 days, 1 hour ago -
Do you have a maintenance window?
by
Susan Bradley
6 hours, 37 minutes ago -
Freshly discovered bug in OpenPGP.js undermines whole point of encrypted comms
by
Nibbled To Death By Ducks
1 day, 4 hours ago -
Cox Communications and Charter Communications to merge
by
not so anon
2 days, 5 hours ago -
Help with WD usb driver on Windows 11
by
Tex265
13 hours, 39 minutes ago -
hibernate activation
by
e_belmont
2 days, 14 hours ago -
Red Hat Enterprise Linux 10 with AI assistant
by
Alex5723
2 days, 18 hours ago -
Windows 11 Insider Preview build 26200.5603 released to DEV
by
joep517
2 days, 21 hours ago -
Windows 11 Insider Preview build 26120.4151 (24H2) released to BETA
by
joep517
2 days, 21 hours ago -
Fixing Windows 24H2 failed KB5058411 install
by
Alex5723
1 day, 17 hours ago -
Out of band for Windows 10
by
Susan Bradley
3 days, 1 hour ago -
Giving UniGetUi a test run.
by
RetiredGeek
3 days, 8 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.