473,800 Members | 2,614 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 cmdImportVendor s_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.AddNe w
rsVendors.Field s(0).Value = strArray(1)
End If
'Loop
rsVendors.Close
End Sub

Nov 13 '05 #1
3 2537
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(strFi leName)
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.File Name = strFileName
myTextFile.NoBl ankLines = True
myTextFile.Coun tOnlyNonBlankLi nes = False
myTextFile.Stri pLeadingSpaces = True
myTextFile.Stri pTrailingSpaces = True
myTextFile.Stri pNulls = False
myTextFile.Only AlphaNumericCha racters = False

rsVendors.Open "tblTEMPVendors ", CurrentProject. Connection,
adOpenDynamic, adLockOptimisti c

intError = myTextFile.cfOp enFile
If intError = 0 Then
While Not myTextFile.EndO fFile ' Watch for the
end of the file
myTextFile.csGe tALine ' 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.AddNe w
rsVendors.Field s(0).Value = strarray(1)
rsVendors.Field s(1).Value = strarray(2)
rsVendors.Field s(2).Value = strarray(3)
rsVendors.Field s(3).Value = strarray(4)
rsVendors.Field s(4).Value = strarray(5)
rsVendors.Field s(5).Value = strarray(6)
rsVendors.Field s(6).Value = strarray(7)
rsVendors.Field s(7).Value = strarray(8)
rsVendors.Field s(8).Value = strarray(9)
rsVendors.Field s(9).Value = strarray(10)
rsVendors.Field s(10).Value = strarray(11)
rsVendors.Field s(11).Value = strarray(12)
rsVendors.Field s(12).Value = strarray(13)
rsVendors.Field s(13).Value = strarray(14)
rsVendors.Field s(14).Value = strarray(15)
If strarray(16) = "x" Then
rsVendors.Field s(15).Value = -1
End If
If strarray(17) = "x" Then
rsVendors.Field s(16).Value = -1
End If
If strarray(18) = "x" Then
rsVendors.Field s(17).Value = -1
End If
If strarray(19) = "x" Then
rsVendors.Field s(18).Value = -1
End If
If strarray(20) = "x" Then
rsVendors.Field s(19).Value = -1
End If

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

myTextFile.cfCl oseFile
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(strFi leName)
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.File Name = strFileName
myTextFile.NoBl ankLines = True
myTextFile.Coun tOnlyNonBlankLi nes = False
myTextFile.Stri pLeadingSpaces = True
myTextFile.Stri pTrailingSpaces = True
myTextFile.Stri pNulls = False
myTextFile.Only AlphaNumericCha racters = False

rsVendors.Open "tblTEMPVendors ", CurrentProject. Connection,
adOpenDynamic, adLockOptimisti c

intError = myTextFile.cfOp enFile
If intError = 0 Then
While Not myTextFile.EndO fFile ' Watch for the
end of the file
myTextFile.csGe tALine ' 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.AddNe w
rsVendors.Field s(0).Value = strarray(1)
rsVendors.Field s(1).Value = strarray(2)
rsVendors.Field s(2).Value = strarray(3)
rsVendors.Field s(3).Value = strarray(4)
rsVendors.Field s(4).Value = strarray(5)
rsVendors.Field s(5).Value = strarray(6)
rsVendors.Field s(6).Value = strarray(7)
rsVendors.Field s(7).Value = strarray(8)
rsVendors.Field s(8).Value = strarray(9)
rsVendors.Field s(9).Value = strarray(10)
rsVendors.Field s(10).Value = strarray(11)
rsVendors.Field s(11).Value = strarray(12)
rsVendors.Field s(12).Value = strarray(13)
rsVendors.Field s(13).Value = strarray(14)
rsVendors.Field s(14).Value = strarray(15)
If strarray(16) = "x" Then
rsVendors.Field s(15).Value = -1
End If
If strarray(17) = "x" Then
rsVendors.Field s(16).Value = -1
End If
If strarray(18) = "x" Then
rsVendors.Field s(17).Value = -1
End If
If strarray(19) = "x" Then
rsVendors.Field s(18).Value = -1
End If
If strarray(20) = "x" Then
rsVendors.Field s(19).Value = -1
End If

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

myTextFile.cfCl oseFile
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
23961
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
1858
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 subsets structure and this way only the existing fields in the destination will be filled? That would be great, but it seems that the append query wants you to specify the fields. is there another way around this? I want to do it in code and it...
0
1757
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 then assigns these values, plus a new receiving number, to the current form. The SQL string is an append query that copies select fields from the PO line items table into the receiving line items table and appends the current receiving number to...
5
5380
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 if I append the data 3 times in succession, it copies the same data over 3x. Now I have copies in triplicate. It used to only transfer records that weren't already there, but not anymore. If I can't get the append to append correctly, I was...
5
2254
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 orders2. But I want to find the highest ordered in the table orders2 instead. In short, I want to append the order from the table orders2 into the table orders1 and this order to get the next highest ordered.Somehow I canot manage it.Can you help...
1
5381
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 those records in the new table to the cooresponding table. Here is my code for the button: ----(start of code)----------------------------------------------------------- ------------------------------------------------------------------- ...
5
2081
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 appends each specific clientId to the table when the command button from form 1 is selected (code below). The 2nd query works as well. But it will only append 1 employee record to the table. I thought this must be because it is only allowing for 1...
4
2414
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 Submitted defaults to 1/1/00 if the cboSubmittedBox field is "No". Otherwise it is selected from a calendar. The Date Entered field defaults to the current date. There are 3 sets of criteria that need to be checked for the update or append to take place. ...
3
1742
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 the Append queires (stDocName40 thru' stDocName45) don't run (info does not append to the table) when I execute the code. I don't see why it doesn't work and I'm confused. Any ideas? I've checked, double checked and triple checked for any...
5
3888
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 multiple players and have entry format such as Warren Spahn/Jim O'Toole/etc.... What I currently have is upon closing out the Stock_Catalog entry form, code runs to append the Player_Name to a table titled Player_Hdr where I then add details about the...
0
9691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10255
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9092
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7582
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.