MS Access unable to locate my excel range when importing - ms-access

I have this code that works on one spreadsheet, but not another. I am just trying to automate the transfer of an excel data range to an access table, like so
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "UsysFastTrack", strFilePath, False, strRange
strFilePath and strRange are just strings that contain the full file path (including the worksheet name and extension) and the name of an excel range in the worksheet, respectively. This line causes an error
The Microsoft Access database engine could not find the object ...
This error appears a lot online and somewhere I saw the advice to try the import wizard to see what I get and lo and behold, right as I hit the last Next
This is the exact same error and it stops me dead in my tracks. What's funny is that you can see the range exists in the spreadsheet before your very eyes.
What's going on here?

Looks like the names of your named ranges are not valid, they are similar to regular ranges. Try to change names

Related

Access VBA Macro to run pass through query

I have a pass through query built in Teradata set to export data to an Excel spreadsheet. I'm trying to automate it, but when I run the macro or open the query, a window pops up asking for the data source. I have an ODBC connection created and I'm thinking there has to be a way to make the macro pass the data source name so it will run without interaction.
Edit: Adding Macro as requested
Function AutoExec()
On Error GoTo AutoExec_Err
DoCmd.OutputTo acOutputQuery, "Performance Interval Data", "ExcelWorkbook(*.xlsx)", _
"filepath\filename.xlsx", False, "", , acExportQualityPrint
DoCmd.Quit acExit
AutoExec_Exit:
Exit Function
AutoExec_Err:
MsgBox Error$
Resume AutoExec_Exit
End Function
Couple of concerns, (can't validate any of this right now as I do not currently have access to Access for testing), but it looks like:
You're trying to OutputTo a query, to the best of my knowledge that
is not feasible.
Your file path is setup as filepath\filename.xlsx unless that is the actual location and name of your Excel sheet, something seems
wrong there to me.
I don't really think this macro relates to an ODBC of any sort in its current state.
But, you should at least start with fixing the filepath issue. That should be the full path to your Excel file and the full name of the file as well. (i.e. C:\TEMP\TestExcelSheet.xlsx)
All that being said, you may want to just go with something like this (although its a little difficult to tell if this is what you actually want or not):
'Export Excel file from Query
DoCmd.TransferSpreadsheet acExport, , "acOutputQuery", _
"C:\TEMP\TestExcelSheet.xlsx", True
NOTE: "acOutputQuery" should be the actual name of your passthrough query, "C:\TEMP\TestExcelSheet.xlsx" would be your destination path, and True adds the query's headers into the sheet, False to ignore the headers.

After splitting database importing excel files gives error 2950

Before splitting my database I was using a macro for importing excel file to my table and it was okey.
Now after splitting database when I use that macro from front-end I got error:
You cannot record your changes because a value you entered violates the
settings defined for this table or list (for example, a value is less than
the minimum or greater than the maximum). Correct the error and try again."
The error number on the Macro Single Step pop-up is 2950.
when i use macro from back-end it does not have problem and works.
please help because i need importing from front-end.
equivalent VBA code for macro i have used is like below, it works from back-end and gives error from the front-end:
DoCmd.TransferSpreadsheet acImport, 8, "Rep_Indicator", "E:\Rep_Indicator", True, ""

Link Excel sheet to Access: #Num! error for numeric values in text-numeric hybrid column

This is about a legacy Access 2003 database that I've inherited. There's some code that links an Excel (97-2003) spreadsheet:
tdf.Connect = "Excel 5.0;HDR=Yes;IMEX=2;DATABASE="&strXLFileName
tdf.SourceTableName = strSourceTableName & "$"
CurrentDb.TableDefs.Append tdf
When I open the linked table afterwards, I see #Num! in place of numeric values in a column that is supposed to contain both numeric and text.
For example, in Excel:
Field1
H88
234
X65
432
Linked table in Access:
Field1
H88
#Num!
X65
#Num!
I've tried the following:(a) changing Excel 5.0 to Excel 8.0, which is more accurate for the format the soruce files are in; (b) importing using DoCmd.TransferSpreadsheet instead of linking.
The first still gives #Num!, while importing gives nulls.
Upgrading to later versions is not an option at the moment - there are a number of places within the code that use things that Application.FileSearch that require careful rewriting and testing.
Anyone know how to get Access 2003 to treat the "numbers" like they were text, too?
TIA!
Change IMEX=2 to IMEX=1 to treat all the values as text.
You can read more about IMEX at Connection strings for Excel 2007.

MS Access: Link to Excel file with header on row X > 1?

I need to link to an Excel file in Access but there are a bunch of needless rows that come before the actual header + data. Is there a way to skip the first few rows when importing this Excel file and tell it where the header is?
Note: I cannot modify the source Excel file directly. The files are provided as-is.
Link the sheet using the Range parameter with DoCmd.TransferSpreadsheet, as in this example from the DoCmd.TransferSpreadsheet Method help topic.
DoCmd.TransferSpreadsheet acImport, 3, _
"Employees","C:\Lotus\Newemps.wk3", True, "A1:G12"

simple import form in Access

how to create an access form which has import excel file button. and after selecting excel file it automatically creates a table in the database with collumn headers as excel first row and data as excel other rows. if you think i am not putting any effort please give me suggestion or reference and ill do it on my own.
For versions of Access since 2003, you can use the File Dialog to allow the user to browse for the file they want, prior to that, you can use API calls. If this is overkill for you, you can have the user type in the file name and path, but you will have to check that it exists using code (Dir may suit).
It would be best to use TransferSpreadsheet method of the DoCmd object (available in any version of Access from, AFAIK, 1997 onward) to import the spreadsheet. This can be run as VBA (code) or a macro.
If we assume that you are able to create a form and wire up a button you have two issues:
The file open dialog.
Triggering the import.
For 1 you should be able to use the standard Microsoft file dialogs - my VB.OLD and Access are spectacularly rusty (no access 2007) but you can reference the appropriate COM assemblies from Access after which it becomes fairly easy.
2 is a bit more interesting - I beleive you can pretty much do this by menu selection from within access in which case, at least as a first step, you should be able to automate the same steps - pretty much anything you can do from a menu you can also do by calling the relevant command from VBA. The more complex solution would be to create VBA logic to create a linked table that links to the Excel file and then do a create table query and then drop the link.
In terms of effort, the form is something one would expect you to be able to do without much help - however automating something like an import from excel is not necessarily obvious.
An example using Access 2003 would be as follows for selecting a file:
Dim fDialog As Office.FileDialog
Dim strFile As String
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.InitialFileName = "C:\temp\*.xls"
.Filters.Clear
.Filters.Add "Excel file", "*.xls"
.Filters.Add "All Files", "*.*"
If .Show = True Then
strFile = .SelectedItems(1)
End If
End With
Debug.Print strFile
Note you would need to add a Reference to the Office 12 Object Library
To Import the file you can use the TransferSpreadsheet Function of the DoCmd Object. For E.g.
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "ExcelImport", strFile, True
The Access table called ExcelImport would have to already exist in the database.