how to speed up with csv and access - ms-access

There are over 210,000 records in a txt file. One record has three columns with space split. To import this file into ms access, system replace spaces into comma. And then using insert into, system imports all at once. System needs to sort and search with these records. The whole processing time is so slow. It takes over 15 minutes. How to speed up?
Is it able to handle over 210,000 records in a table of ms access
2003?
Without replacing comma, could we import this txt file into access?
Thank you.

Access can import a text file which uses spaces instead of commas as the delimiter. On the first page of the Access 2003 "Import Text Wizard", choose the radio button next to "Delimited - Characters such as comma or tab separate each field". Click "Next", and on the next wizard page, select the radio button next to "Space" under the "Choose the delimiter that separates your fields" heading.
You can save your import choices as an "Import Specification" by click the "Advanced..." button to bring up the Import Specification dialog, then clicking the "Save As..." button on the right. Assign a Specification Name in the "Save Import/Export Specification" dialog and click OK.
If you want to do this type of import operation with code, you can use the TransferText method:
DoCmd.TransferText acImportDelim, "Your Named Specification", _
"Destination Table Name", "C:\somepath\yourfile.txt"
See Access' help topic for more details about the TransferText method.
I noticed your question includes a vb6 tag, but don't know how that fits in. Seems to me that using TransferText from VBA to import a text file of 210K rows of 3 columns should not take anywhere near 15 minutes.

Related

I need to open a report from a set of similar reports based on a feild value in a form

I have a MS access data base which has a form from which I want to open a report. There is a choice of 26 reports which all have different name which is a numeric value eg 221.1, 221.2 113.3, etc etc. I have an unbound field in the form which adds the values of four other bound fields and returns a number which should match one of the report names. I have called this unbound field "report Name". I want to add a button that is pressed which opens a report that has the same name as the value in the "report name" field so that if the value is 221.1 it will open report named 221.1 and so on...
I am not used to coding in access and generally rely on the built in commands, macros, wizards etc but in this case I don't think there is a suitable "wizard" to use. Any ideas or help on how I can do this would be gratefully received. I am working in Access 2013 but the data base was written in 2007 and transferred over.
You can get away with just a tiny bit of code in your button's click handler:
Private Sub MyButton_Click()
DoCmd.OpenReport Me![report Name]
End Sub
Add the code just like adding an embedded macro, but by choosing Code Builder instead of Macro Builder. The first and last line should already be there.

what control should I use to print a long message to a windows in access VBA 2007

I am writting a test code in access 2007 (VBA) that would test the data and report if any record has problem.
It would do it by checking data with external data, so I am not using any of the access reporting tools.
This is an internal tools and will be used only by me, so the UI is not that important.
What I am doing is to write a VBA code that read recordset and external data and check the recordset.
I can do this, but I need a way to print this on UI. Something such as this:
Record no 10 is not valid : reason XXXX
Record 15 is not valid: reason YYYY
I was thinking of using a multi line text box to output this on screen, but I have several problem:
I can not find any way to make a text box as a multi line text box. There is no multi line propertyso I can output a line break.
If the size of recordset is big and there are a lot of errors, I am getting error that the size pro text proprty is too big.
What control should I use? I was thinking about using a label control, but I'm not sure if it's possible.
The easiest way is to use Debug.Print (output goes to the Immediate window -> Ctrl+g).
An Access text box that is large enough is always multi-line capable, there is no special property for that. Just append vbCrLf to each line to create a line break.
Me.txtLog = Me.txtLog & strError & vbCrLf
But for really long text output, a log file is the best option.
To write text files: either use FileSystemObject or the old fashioned Open statement.
The UserForm control in VBA has a MultiLine property, which you can set to True.
The other property is the EnterKeyBehavior that needs to be set to True to allow line breaks.
Alternately yes, you could use a Label control to achieve the same and even format it to look like a TextBox if you care.
But if long string of data, I would consider outputing it straight to a file with Open and For Output or For Append.

import tab-delimited txt into Access table using VBA

I am trying to import a tab-delimited txt file into an Access table using VBA. In my code, I want to insert it into a table that has not yet been created.
Here is what I tried doing. Note - I was able to make this work with a CSV, and without including this: DataType:=xlDelimited, Tab:=True
Sub InsertData()
'import CSV into temp table
DoCmd.TransferText TransferType:=acLinkDelim, TableName:="tbl_TEMP", _
FileName:=FileNameVariable, HasFieldNames:=True, DataType:=xlDelimited, Tab:=True
End Sub
When I run this block, I get the following error on DataType:=xlDelimited, Tab:=True
Compile error: Named argument not found
How should I change this in order to pull in the tab-delimited txt file so each column from the txt has its own column in Access?
As you have seen from the other articles on the topic, there really isn't a generic way to import tab-delimited text files. All of the other solutions I've seen say that you should import the tab-delimited text file once, save the import specification, and then use that import specification for all subsequent imports. The problem there is that if you want to import a different tab-delimited file the specification may not match.
The only way I've found to do it generically (short of "rolling your own" code using FileSystemObject, Split(s, vbTab), etc.) is to create a completely generic specification for all 255 possible fields and use that. It requires a one-time setup as follows:
Copy the CSV data from the Pastebin here, paste it into your favorite text editor, and save it as GenericTabSpecification.csv.
Open that file in Excel, select all 256 rows and 4 columns, then hit Ctrl+C to copy.
In Access, start the import wizard for text files and choose any tab-delimited file. (We won't actually be importing it.)
When you get to the first page in the wizard, click the "Advanced..." button.
In the Import Specification dialog, verify the settings (Field Delimiter, Text Qualifier, etc.) then click the top-left corner of the Field Information grid so all rows are selected:
Hit Ctrl+V to paste the data from Excel into the grid. The grid should now contain 255 rows.
Click the "Save As..." button and name the specification GenericTabSpecification. Once that is done, cancel out of the wizard.
Now we can do a generic import from VBA using a statement like this
DoCmd.TransferText _
TransferType:=acImportDelim, _
SpecificationName:="GenericTabSpecification", _
TableName:="newTable", _
FileName:="C:\Users\Gord\Desktop\foo.txt", _
HasFieldNames:=False

Import CSV data from web service into Excel

I have written a simple web service that returns large volumes of csv data. I will to import this into Excel in a tabular format using Excel's "Data From Web" function.
Is there a way to get Excel to automatically parse the csv fields returned into individual columns as part of the import operation?
At present the only means I have for doing this is to first import the data into a single column and then write VBA code to select the data and split it using TextToColumns. This feels messy / error-prone.
The other alternative I have is to modify the web server to serve back the data as HTML. However, I'm reluctant to do this as adding tags around each csv field will greatly impact the volume of data returned.
Adamski,
Here is something that I use. I found the core somewhere on the internet, but don't know where.
What it does is it opens a tab separated file and reads the data in an excel sheet
If Answer1 = vbYes Then 'I asked prior if to import a tab separated file
Sheets("ZHRNL111").Select 'Select the sheet to dump the data
On Error Resume Next
With ActiveSheet
If .AutoFilterMode Then .ShowAllData 'undo any autofilters
End With
Sheets("ZHRNL111").Cells.Clear 'remove any previous data
On Error GoTo 0
Range("A1").CurrentRegion.Delete
Fname = MyPath & "\LatestReports\Report-111.tsv"
Open Fname For Input As #1
iRow = 1
Line Input #1, Record
On Error Resume Next
Do Until EOF(1)
P = Split(Record, vbTab)
For iCol = 1 To 14
Cells(iRow, iCol) = P(iCol - 1)
Next iCol
iRow = iRow + 1
Line Input #1, Record
Loop
On Error GoTo 0
Close 1
End If
Regards,
Robert Ilbrink
Depending on the version of excel you are running you should be able to open the .csv in excel and use the text to columns feature built into excel.
Also, if you could modify your csv to split columns based on commas "," instead of tabs excel would open it directly without the need to format it.
I know however this can sometimes be a problem depending on the data you are importing because if the data contains a comma it must be inside quotations.
In my experience the best way is to use quotations on every field if possible.
Hope this helps.
I am actually creating a product right now to do this in both XML and JSON for Excel. I know comma delimited does work in Excel, with some caveats. One way around it is to put some "" around the text in between the delimiters for the "Data From Web" feature. There are still issues with that however. I did find that despite it's increased size, XML was the best option for quick turn around. I was able to create the service and hand my project manager the Excel document which he could update at anytime.

Microsoft Access TransferText function: problem with codepage

I inherited a huge, bulky MS Access database and am assigned to solve a problem in it. The problem is as follow...
System A exports its data to a pipeline-delimited .txt file. The files has special characters working correctly, for example the value "Müller" shows when opening this file in notepad or Excel.
Next, the Access DB imports the .txt file and stores the result in an internal employees table. The last name field is of data type "memo". The method to import data from the .txt file to MS Access is as follow:
Call DoCmd.TransferText(acImportDelim, _
"tblEmployees", _
"tblEmployees", _
me.txtImportFile, _
True)
After running this import and viewing the employees table I noticed that names with special characters are screwed up. "Müller" becomes "M├⌐ller" for example. I investigated some online help and found out that can include a "codepage" parameter in the TransferText call, so I set it to 65001 (which appearantly is the codepage for unicode):
Call DoCmd.TransferText(acImportDelim, _
"tblEmployees", _
"tblEmployees", _
me.txtImportFile, _
True, _
, _
65001)
Now that I have ran the import script again, I see no difference whatsoever, the special characters are still misformed. I'm running out of steam so I hope one of you has some advise on how to resolve this...
Both versions of your TransferText operation are using a SpecificationName named tblEmployees. What Code Page is specified in that Specification?
Try importing the text file manually. Choose "Advanced" from the Import Text Wizard. Then select Unicode in the Code Page list box. You may need to test with different Code Page selections until you find which one imports your text correctly.
Which ever Code Page selection works, save your choices as a specification and use it in your TransferText command, without supplying a separate CodePage parameter.
Using CodePage=1200 (msoEncodingUnicodeLittleEndian) solved the issue in my case.
there is an unicode list to use in VBA:
http://msdn.microsoft.com/en-us/library/office/aa432511(v=office.12).aspx