Import Discontiguous Excel Columns to Access - ms-access

strRange = "C:C,H:H,J:J,S:S,AA:AA"
DoCmd.TransferSpreadsheet , cSpreadsheetTypeExcel12Xml, "tbl_adds", strInputFileName, True, stRange
The spreadsheet in question has 40 columns of which I only need 5 (listed in stRange)
Is this a syntax thing or do I have to use a different method?

Don't import but link the worksheet.
Create a simple select query with the linked table as source. In this, mark the five columns in question and save the query.
Now use this query for your import.

Related

Importing specific columns from a CSV into excel

I am trying to do what the title says and also do it for new records. I cannot link the CSV file because it exceeds the 255 limit. So i am attempting to split up the table.
I have the below table in access
DateOfTest
Time
PromptTime
TestSequence
PATResults
Logs
Serial Number
1
2
3
4
5
6
7
Obviously, where the numbers are i want the data from the CSV to be inserted.
I have created a form including a button so i can run some VBA, but i cannot find the correct information online for my work, as i am new to VBA it is also a bit confusing.
I have attempted some random code, but i was just spraying and praying at that point
I am not sure I understood your question. In the impoer tool you can choose columns, but if you want to do it with a script, I would suggest to perform pre-processing phase with simple python and pandas to read the csv file, remove any unwanted columns and save to another CSV to be uploaded directly to excel.
something like this
import pandas as pd
df = pd.read_csv ('csvfile.csv')
df.drop('column_name', inplace=True, axis=1)
df.to_excel ('filename.xlsx', index = False, header=True)

Import txt file into ms access m:m table

I'm quite new to MS Access. I just set up a new Access database to be used with our schematics tool. Our tool can access the database, so this works fine. At the end of our schematics capturing process, we generate a bill of material (BOM), listing every part that is in the design.
I want to be able to evaluate which part (each has a unique part ID "TUPID") is used on which board (unique board-ID "UBRID") - so I set up a Many-to-Many-table. First tests entering some data there by hand look good, importing text-files containing "UBRID", "TUPID" works fine too.
Now I want to be able to import the generated BOM, which is plain text containing only the "TUPID" - the "UBRID" is not known by the schematics tool. I know, I can manipulate the text file before I run a query, but I would rather not. I want to start the import operation from a form, which lists all boards (thus getting the "UBRID" by selecting the relevant board) then I want to start the import - but how is this done? Do I have to run a query for each line of the text file, or what is the best way to achieve my goal?
Looking forward for any tips!
Assuming import is for one UBRID set at a time - import records then run UPDATE action to populate those records with UBRID. Something like:
CurrentDb.Execute "UPDATE tablename SET UBRID = '" & Me.UBRID & "' WHERE UBRID IS NUll"

Importing a lot of csv's in MSAccess using a macro [duplicate]

I need to skip the first three lines of a CSV file when loading into MS Access. The default CSV import does not drop the first three lines. I am thinking of writing a macro to ignore the first three lines.
My research has shown the DoCmd object but its methods do not cater to drop the first x lines.
Any thoughts?
The DoCmd.TransferText method takes a SpecificationName as one of its arguments. Follow the instructions at How to Create an Import Specification to create and save an import specification.
Now go into Access Options, Navigation Options, and show hidden/system objects. You should now be able to open a table named 'mSysIMEXSpecs'. Find the import spec you created earlier based on the SpecName column. Change the 'StartRow' column for that import spec to 3 (the StartRow is zero-based).
Now you should be able to use the DoCmd.TransferText method passing the name of the import spec you created and it will skip your first three lines.
In Access VBA I would use two TextStream objects, one to .ReadLine the original CSV file line-by-line and the other to .WriteLine to a temporary file, skipping the first three lines of the input file. Do some web searches on Scripting.FileSystemObject and I'm sure you'll find some sample code for this.
Then I would use DoCmd.TransferText acImportDelim to import the temporary file into Access.
The Docmd.TransferText method is a good option to go with but as an alternative to modifying your import spec, you could consider importing everything and doing some validation after the import.
So you could, import the entire file and then use a delete query to delete data from the table.
As mentioned in a comment above, modifying the spec via a system table could be tricky for someone else to find where-as a delete query with a nice little comment in your code could work a treat. If it's required use it, if not it could be commented out.

Automatic formula calculation in excel

I have a small query regarding automatic formula value calculation in excel.
In my project I will be having 200 questions and corresponding 200 answers( numerical values of 10,20 and 30). Those questions and answers are obtained from webpages and all the questions and answers are stored in my sql database. I will collect the answers that are posted in mysql database to excel with the help of mysql add-in.
My question is I have some formulas
given in my excel sheet ex:mean(C204), STDEV(C205), final risk( my own formula F209)
I want the formulas to automatically calculate the formula values whenever I import the
data from mysql. Is it possible in excel if not is there any alternative? Please help!
This is kind of a stab in the dark since I'm not at all familiar with the add in or how it operates. It seems odd that it would import data and not allow a application.calculate event to take place after import.
Perhaps... you can run the application.calculate method on worksheet change. In your VBE, double click the worksheet upon which the mysql data is dropped. Then add this code to that worksheet:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.Calculate
End Sub
There's fairly good chance that the add in also snuffs events by setting application.enableEvents = false which means this won't work, but... it's worth a shot.

Import error for large negative numbers from CSV to Access using TransferText

I'm importing data from a CSV file into an Access table. The number is something like
-21000000 (-2.1E7). I'm using TransferText to do the import.
DoCmd.TransferText acImportDelim, , "matching report temp", Source_folder & "\" & Source
In the "matching report temp" table, the field is set up as Double. The import generates a type conversion failure. However, when I open the CSV file in Excel and copy the offending row, I can successfully use Paste Append to add it to the table manually - so the number doesn't exceed the capacity of the field.
As far as I can tell, this only happens with large negative numbers. Smaller numbers, and positive numbers of the same magnitude seem to import fine. I know I can specify an Import Specification in TransferText, but I don't see a way to set the field type to Double.
How can I get around this problem? I don't want to have to manually track down the import errors and append them by hand.
Don't let TransferText create the Access table for you. Create the Access destination table first and assign the field types you need.
When you run TransferText, the CSV data will be appended to that existing table. It should work without error as long as you choose compatible data types for the Access fields.
I examined your CSV file. The header row is troublesome because some field names are missing:
Reporting Unit,,$ Dollars,Offset Unit,,$ Dollars,Variance
That seemed to be a complication for DoCmd.TransferText. So I imported manually from the Access UI. And that gave me an import error on row 49 with the 3rd and 6th columns. In Access, the destination fields were both created as Long Integer. However the values for those fields in the CSV row are 2262169190 and -2262169190 ... both beyond the capacity of Access' Long Integer, -2,147,483,648 to 2,147,483,647.
As a cheap workaround, I selected Text for the data type of those 2 columns when I imported. That allowed the import to work without error. Once you get the data into Access successfully, you could cast those (string) values to a numeric type when you need to use them.
It also worked when I chose Double as the type for those 2 columns. It sounds like that's what you actually want.
If you want to get the import working with DoCmd.TransferText, I think you'll need to create an import specification. If possible, I would also first modify the header line of the CSV file so that all the fields have names.
I actually tested that approach without altering the CSV file. After creating an import specification in the Access UI (see screen capture below), this TransferText operation worked in Access 2007 without import errors.
DoCmd.TransferText acImportDelim, _
"IC_Y1301_Specification", _
"IC_Y1301_LD10279_F25210001", _
"C:\Users\hans\Downloads\IC_Y1301_LD10279_F25210001.CSV", _
True