Open Import Text Wizard in Access 2013 through VBA - ms-access

I'm trying to open the Import Text Wizard as part of my code after it's ftp'd down a text file.
I don't have the metadata of the file as each file could be different, the only things they have in common is that they are pipe delimited with no text qualifier with a header row. No consistency in column type or number of columns.
Hence I don't think I can easily use docmd.transfertext as the specification would have to be different each time.
I don't mind pushing people down the manual route but if I look this up the instructions are to use Docmd.RunCommand acCmdImport. This appears to then be deprecated after Access 2007 as if I run it I get Run-time error 2002 saying the function or feature isn't installed in this version.
What I'm after is either:
A way to open the wizard
or
A way to import / link the text files without knowing the metadata ahead of the import.

The command is:
Docmd.RunCommand(acCmdImportAttachText)
That opens the wizard as if you called it from the band.

Related

How to remove spaces from field names when importing external data into MS Access 2010

I have an external file that I don't create which I need to import on a rolling basis, most of the column headers/field names have spaces in them. Is there a query I can write to change all of them at once? I'd rather not write a long query to get rid of spaces for each individual field name. The field names are always the same and in the same order in the file, the spaces are in the middle of the field names (ex: "Employee Number").
First of all, "query" refers to an SQL statement (including those viewed in Design View) that retrieve or act on data already in the database. Importing data from an external file is a separate action, not generally called a query. So strictly speaking the answer is "no".
However, Access does have built-in import functionality in Access. I suppose you can call these import "functions" or "actions" or "processes", just not queries. And I'm not being a smart aleck, since much of getting help with applications and code is learning and using the correct terms.
Go to the External Data ribbon (a.k.a. toolbar) along the top of Access.
Click the Import Text File icon (careful not to click the Export Text File icon, since they look similar. Hover the mouse cursor over each button to see the text description of it).
Choose the filename, and pick which import option
As Gustav instructs in his answer, choosing "Link to data source by creating a linked table" is the most efficient solution for external files that don't change format. The linked table (hence the external file) can be re-queried without repeating numerous steps.
Walk through the Import Wizard steps. Play with the options if you need to figure it all out.
In particular, make sure to check "First Row Contains Field Names"
On one of the wizard steps, you can edit the field names to remove the spaces.
On the last step, click the "Save Import Steps" checkbox, specify a name, then click the "Save Import" button
To re-use the previously-saved import steps:
Go to the External Data ribbon (a.k.a. toolbar) along the top of Access.
Click "Saved Imports" button
Choose your saved import settings
Click Run
OR if you created a Linked table
There is no need to "re-import". Instead, a normal Access query can be used to get the data and update one of your normal data tables.
If the path of the external files changes, this can also be updated by right-clicking the linked table and choosing Linked Table Manager (also available on the External Data ribbon). Select the table in the list and also check "Always prompt for new location" before clicking OK. A standard file selection dialogue will be shown for selecting a new filepath.
(Just to be complete, it is also possible to write VBA code in Access to open a file, read and analyze the headers and then import the data according to your custom behavior, but this isn't for you if you'd "rather not write a long..." something to do this.)
I'd rather not write a long query to get rid of spaces for each individual field name.
Maybe not, but there is no smart way to overcome this.
However, don't import the file but link it. Then use the linked file as source in your query. In this, alias the field names as you prefer, and do basic filtering and conversion of data. Then use this query for your further processing.

SSIS Handling a Flat File Missing a Text Qualifier

I'm currently designing as SSIS package to import some CSV files and needs to account for various error types. One of the errors is an incorrect or missing text qualifier.
I.E: "col1","col2","col3/,"col4"
The package is currently throwing the error "[ProductMaster CSV [66]] Error: The column delimiter for column "Column 2" was not found.".
Which is what I would expect to see in this situation.
Apparently getting the file initially sent in the correct format isn't an option at the moment.
I've tried changing the file to have no text qualifier, but this then falls over if there is a comma in a field so is not a viable solution.
Is there any way of handling this?
I use a third party tool to read csv files and it handles this type of situation. If you must do something on your own I would import the entire line to one column and then parse it with either a stored procedure or a script component.
There are plenty of solutions out there, some free and some with a minimal cost.
I have never found a way to handle this with SSIS connection managers 'out of the box'.
To solve this issue, look at your file format. Use text editor like Notepad++ and if your file is CR, make sure you don't use (") instead choose in the text qualifier and choose CR in the header row. This should work 100%

Importing text file to Access database in Windows 7

I am trying to import data from a text file to Access 2007 and 2010, delimited by vertical bar. I use Import Text Wizard of MS Access, but when I try to import it after choosing appropriate delimiter (preview looks fine), I get the following error:
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
There are no primary keys, nor relationships, as it is just a text file. I was able to insert this text file in Windows XP, but the problem arises in Windows 7. I was able to successfully export the data into Excel. I also set Indexed to No in Field Options of Import Text Wizard, but that didn't help either.
Any help would be greatly appreciated, as I couldn't find any useful info anywhere.
Edit: I tried inserting into new and existing tables, even a new database (accdb and mdb format), every time I get the same error.
Edit2: I opened the text file in WordPad, and saved it again as txt file, the Access didn't generate any error. The previous txt file didn't show the new lines, but Access was still aware where each record ends, and preview looked fine. The new text file specifically shows new lines (each record separately). If someone has a suggestion about how to overcome this issue without creating a new txt file, please let me know
I don't think there is anything you can do except convert the file to Windows CRLF format.
Although I wouldn't use WordPad for this, but Notepad++.
It has an explicit command for this: Edit -> EOL conversion, and you can be fairly sure that it won't change anything else in your file (I wouldn't be so sure about WordPad).
Actually most text editors that are more sophisticated than Notepad have a command for this, I think. :)

MySQL Workbench 6.1 - Error importing recordset

I'm going to be getting a new computer soon and I don't want to lose all of the data I have entered in my tables, so I decided to test out the feature that allows you to export and import CSV files. I exported a table successfully (data was transferred to Microsoft Excel in CSV file), but when I opened the file in Microsoft Excel and added a few rows and tried to import it back in to MySQL Workbench, I got the following error:
"Error importing recordset
error calling Python module function
SQLIDEUtils.importRecordsetDataFromFile"
I've searched all over for info on this, but can't find any solutions. Does anyone know what I'm doing wrong?
In Workbench, open a MySQL connection and then navigate to [Server] --> [Data Export]. There are several backup options here, including saving the data as an individual file or folder. Choose the databases you want to export, and then click [Start Export].
If you ever prefer using Excel for editing and such, then use the MySQL for Excel plugin to access MySQL databases from within Excel. However, I don't think you need it here.
To export your mySQL data, use mysqldump, which will create all the schema for you.
Excel probably added some stuff to your file and now mySQL can't understand it. The best way to find out is by comparing the files before and after the change.
That error indicates a format problem. If the file is small enough, try opening it in wordpad (or the mac equivalent) and see if there's any difference in the formatting? Could be that the delimiting got a little messed up (this can happen especially with end of row markers in MySQL, I've noticed, it can also happen in mac to pc handoffs). If all else fails you could try exporting using a different format and see if that makes a difference (maybe tsv) when you add new rows.
Another reason can be the line endings used. Depending on the system and editor used to work with the cvs file it the line endings might get changed. For me mysql supported UNIX line endings. And in the editor the line ending had been set to MAC OS 9 since I was using a MAC.
Changing it to UNIX line ending worked.
I found that it might be due to a wrong encoding of the input file.
Using Notepad++ for example (or another similar editor) you need to change file encoding to UTF-8.

Issues with Access parsing double quotes in a CSV file

I have a large CSV file that I am trying to import into Microsoft Access but I am running into issues. Assume pipes represent different cells in the database
Assume my content is the below. The second entry will only parse the word my with default settings and will not import the word content into the database even though the import wizard implies that it will. The default settings being , delimiter and " text qualifier.
|my content is good|
|my|
Now if i change the text qualifier to NONE it parses the entire second entry and my content will be imported into the database however the first entry will wind up being in 3 different cells in the data base and will show up as
my|content|is|good.
|my content
I used pipes to imply different cells.
This seems like a limitation in Microsoft Access. Is anyone familiar with a workaround for this?
Original content:
,"my,content,is,good","",
,my"content","",
I am using the import wizard
Yes, this is a limitation of the CSV import capabilities in Access. For whatever reason, Access has always been more restrictive than Excel in its abilities to parse CSV files.
So, one workaround would be to open the CSV file in Excel, save the file as an actual Excel sheet, and then import the Excel sheet into Access. For example, the CSV file
this,is,a "test",CSV file,"Ugly, yes, but still parsable."
is "non-standard" (if one is willing to concede that there is such a thing as a CSV "standard"), and Access cannot import it directly. (It either complains of an "Unparsable Record" or it splits the last field on the commas, depending on the "Text Qualifier" setting.)
However, we can open it in Excel
save the file as "foo.xlsx", and then import the .xlsx file into Access