473,396 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Append String to Table

I have used the import class module from
http://www.mvps.org/access/modules/mdl0057.htm. This reads my text file
into a string called myString. I am trying to append this string into
table tblTEMPVendors. The string is tab delimited. I am trying to use
the code below to do this but I need some help - How do I loop through
the string if this was a recordset I know i would use do while not
rs.eof but I can't get the syntax for a string variable.

Can anyone help?
Private Sub cmdImportVendors_Click()
Dim rsVendors As New ADODB.Recordset
Dim strAppendSQL As String
Dim strArray() As String

'Call function to return file to import
GetFName
'Call read file procedure
ReadAFile (strFName)

rsVendors.Open "tblTEMPVendors", CurrentProject.Connection,
adOpenDynamic
'Do While '???
strArray = Split(myString, vbTab)
If Not strArray(1) = "Vendor" Then 'exclude column heading
rsVendors.AddNew
rsVendors.Fields(0).Value = strArray(1)
End If
'Loop
rsVendors.Close
End Sub

Nov 13 '05 #1
3 2492
what does your text file look like?

what's the strAppendSQL stuff for? Why not just use the Add method of
the recordset object?

Well, how about this - explain what you have (VERY briefly), and the
basic logic of what you want. After that, it's implementation, and
that's easy.

If the only difference between one file and another is whether it has
field names, then create two import specs (one for each), and then peek
at the first line of the file and stuff it into a variable. If it's
text, then you'd use something like TransferText with a canned import
spec that stated that the first line is column names, otherwise you'd
use TransferText with a different import spec that stated that there
were no column names.

Then you don't need Split, arrays, or any of the rest of that stuff.
So you open a file maybe twice. So what? If you have lots of files,
you can have your code iterate over all the files in a directory and
process them. Much faster than doing it by hand, even if your code
does do some slightly redundant things.

Nov 13 '05 #2
what does your text file look like?

The text is exported from our accounting system but is not very tidy,
therefor I used the import class i mentioned to tidy it up a bit.

what's the strAppendSQL stuff for? Why not just use the Add method of
the recordset object?

I should have removed this, no longer used

I have now got the jist of the code I will be using posted below for
anyone who is interested.

Thanks for your help.

Public Sub ReadAFile(strFileName)
Dim myTextFile As New cImportClass
Dim intError As Integer
Dim strVendor As String
Dim rsVendors As New ADODB.Recordset
Dim myString As String
Dim strarray() As String

myTextFile.FileName = strFileName
myTextFile.NoBlankLines = True
myTextFile.CountOnlyNonBlankLines = False
myTextFile.StripLeadingSpaces = True
myTextFile.StripTrailingSpaces = True
myTextFile.StripNulls = False
myTextFile.OnlyAlphaNumericCharacters = False

rsVendors.Open "tblTEMPVendors", CurrentProject.Connection,
adOpenDynamic, adLockOptimistic

intError = myTextFile.cfOpenFile
If intError = 0 Then
While Not myTextFile.EndOfFile ' Watch for the
end of the file
myTextFile.csGetALine ' Tells the class
to go to a new line
myString = myTextFile.Text ' set your string
= to the current string of the class
If myString <> "" Then
strarray = Split(myString, vbTab)
If Not Mid(strarray(0), 3, 1) = "." Then 'exclude date
If Not strarray(1) = "Vendor" Then 'exclude column
heading
rsVendors.AddNew
rsVendors.Fields(0).Value = strarray(1)
rsVendors.Fields(1).Value = strarray(2)
rsVendors.Fields(2).Value = strarray(3)
rsVendors.Fields(3).Value = strarray(4)
rsVendors.Fields(4).Value = strarray(5)
rsVendors.Fields(5).Value = strarray(6)
rsVendors.Fields(6).Value = strarray(7)
rsVendors.Fields(7).Value = strarray(8)
rsVendors.Fields(8).Value = strarray(9)
rsVendors.Fields(9).Value = strarray(10)
rsVendors.Fields(10).Value = strarray(11)
rsVendors.Fields(11).Value = strarray(12)
rsVendors.Fields(12).Value = strarray(13)
rsVendors.Fields(13).Value = strarray(14)
rsVendors.Fields(14).Value = strarray(15)
If strarray(16) = "x" Then
rsVendors.Fields(15).Value = -1
End If
If strarray(17) = "x" Then
rsVendors.Fields(16).Value = -1
End If
If strarray(18) = "x" Then
rsVendors.Fields(17).Value = -1
End If
If strarray(19) = "x" Then
rsVendors.Fields(18).Value = -1
End If
If strarray(20) = "x" Then
rsVendors.Fields(19).Value = -1
End If

End If
End If
End If
Wend
Else
' handle the error here!
MsgBox Error(intError)
End If

myTextFile.cfCloseFile
Set myTextFile = Nothing
rsVendors.Close
End Sub

Nov 13 '05 #3
what does your text file look like?

The text is exported from our accounting system but is not very tidy,
therefor I used the import class i mentioned to tidy it up a bit.

what's the strAppendSQL stuff for? Why not just use the Add method of
the recordset object?

I should have removed this, no longer used

I have now got the jist of the code I will be using posted below for
anyone who is interested.

Thanks for your help.

Public Sub ReadAFile(strFileName)
Dim myTextFile As New cImportClass
Dim intError As Integer
Dim strVendor As String
Dim rsVendors As New ADODB.Recordset
Dim myString As String
Dim strarray() As String

myTextFile.FileName = strFileName
myTextFile.NoBlankLines = True
myTextFile.CountOnlyNonBlankLines = False
myTextFile.StripLeadingSpaces = True
myTextFile.StripTrailingSpaces = True
myTextFile.StripNulls = False
myTextFile.OnlyAlphaNumericCharacters = False

rsVendors.Open "tblTEMPVendors", CurrentProject.Connection,
adOpenDynamic, adLockOptimistic

intError = myTextFile.cfOpenFile
If intError = 0 Then
While Not myTextFile.EndOfFile ' Watch for the
end of the file
myTextFile.csGetALine ' Tells the class
to go to a new line
myString = myTextFile.Text ' set your string
= to the current string of the class
If myString <> "" Then
strarray = Split(myString, vbTab)
If Not Mid(strarray(0), 3, 1) = "." Then 'exclude date
If Not strarray(1) = "Vendor" Then 'exclude column
heading
rsVendors.AddNew
rsVendors.Fields(0).Value = strarray(1)
rsVendors.Fields(1).Value = strarray(2)
rsVendors.Fields(2).Value = strarray(3)
rsVendors.Fields(3).Value = strarray(4)
rsVendors.Fields(4).Value = strarray(5)
rsVendors.Fields(5).Value = strarray(6)
rsVendors.Fields(6).Value = strarray(7)
rsVendors.Fields(7).Value = strarray(8)
rsVendors.Fields(8).Value = strarray(9)
rsVendors.Fields(9).Value = strarray(10)
rsVendors.Fields(10).Value = strarray(11)
rsVendors.Fields(11).Value = strarray(12)
rsVendors.Fields(12).Value = strarray(13)
rsVendors.Fields(13).Value = strarray(14)
rsVendors.Fields(14).Value = strarray(15)
If strarray(16) = "x" Then
rsVendors.Fields(15).Value = -1
End If
If strarray(17) = "x" Then
rsVendors.Fields(16).Value = -1
End If
If strarray(18) = "x" Then
rsVendors.Fields(17).Value = -1
End If
If strarray(19) = "x" Then
rsVendors.Fields(18).Value = -1
End If
If strarray(20) = "x" Then
rsVendors.Fields(19).Value = -1
End If

End If
End If
End If
Wend
Else
' handle the error here!
MsgBox Error(intError)
End If

myTextFile.cfCloseFile
Set myTextFile = Nothing
rsVendors.Close
End Sub

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
2
by: Danny | last post by:
I want to extract a subset of fields from one table into another the master table has many fields the subset has about half, but still many. Is there a way I can just append the master into the...
0
by: karinski | last post by:
Hi All, I have a split f/e - b/e setup on my database with RWOP queries on the front end. The code below gets a PO number(s), and vendor name from a multi choice list box on another form. It...
5
by: Michael C via AccessMonster.com | last post by:
Hello, I have a table that I am appending 3 seperate tables into. My main problem is that each time I append the data, it simply adds to the data already there. That might sound ok, except that...
5
by: solar | last post by:
I have copied a function that appends from table orders2 into table orders1 the row that has the value SubOrder = True in the table orders2. This function finds the highest ordered in the table...
1
by: socasteel21 via AccessMonster.com | last post by:
I have a spreadsheet that has 3 tabs each of the worksheets is setup exactly like a cooresponding table in Access. I created a button that should import each tab to a new table and then append...
5
by: robertmeyer1 | last post by:
Hey, I have 2 append queries. The first is based off of code given and works great. For the second, I followed the format of the 1st and adjusted it to meet my needs. Query 1 works great. It...
4
by: dougmeece | last post by:
Morning Everyone... I have a table that needs to be append to and also updated. All the fields in the table are populated with data from the text boxes and combo boxes on a form. The Date...
3
by: lukethegooner | last post by:
I can't see the wood for the tree's here, I have some code set up to run through a bunch of delete queries, re-append fresh information to local DB tables then run a report. But in the code below...
5
by: HSXWillH | last post by:
I have a table entitled Stock_Catalog. Fields include Stock_ID (random autonumber), Brand, Card_Number and Player_Name. Most of the entries have 1 name in the Player_Name field, but some show...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.