I have an MS Access VBA code but, using it in 2016 version, getting an error.
I have tried to remove the optional part acSpreadsheetTypeExcel12XML
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, TableName:="Drops_Airports", FileName:=out_file, Hasfieldnames:=True, Range:="Airports"
The error on this code is:
Run time error 31532-MS Access was unable to export the data
.
remove the Range parameter. As stated in the documentation:
A string expression that's a valid range of cells or the name of a range in the spreadsheet. This argument applies only to importing. Leave this argument blank to import the entire spreadsheet. When you export to a spreadsheet, you must leave this argument blank. If you enter a range, the export will fail.
Related
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.
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, ""
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
I want to register a function kind of CalculateHours(work_hour, rest_hour) to Excel VBA, in an Addin like Works.xla
I tried using Application.MacroOptions to register the function. The following code is in a Class file, the function is in another module file. They would load when we open Excel and the Addin.
Code:
Private Function AddFunctions()
With MyFunction
Application.MacroOptions .Name, _
.Description, , , , , .Category, , , .HelpFilePath
End With
End Function
Expectation:
I wanna get the argument help, function description in Excel function wizard as other built-in functions. With the help button link to my help file.
Result:
Error number: 1004 Application-defined or object-defined error
or
Method "MacroOptions" of object "_Application" failed
Is there anything (or everything) wrong?
I have kind of 10 functions and need to add them automatically to Excel function wizard every time load the Addin.
07/12/2016 well after dragging my function around following pieces of advise from some posts and doing a number of other pointless things, I found this error happens if Application.MacroOptions Description:=FuncDesc exceeds 255 characters. So essentially don't get too verbose with the description of your user defined function, or just add a
If Len(FuncDesc) > 255 then
Scary warning message about Run-time error '1004'
End if
Another possible issue (and solution) that was affecting me... The function code needs to be written in a module - if it it written in the ThisWorkbook page, Excel won't be able to find the code.
For ease of future readers, here is a compilation of the multiple answers (i.e. list of potential things to check)...
The function code needs to be written in a module (not ThisWorkbook)
Make sure the function description does not exceed 255 characters
If defined in another workbook, try including the workbook name - e.g. Macro:="'PERSONAL.xlsb'!Macro/UDF_Name"
If defined in an Excel add-in, call ThisWorkbook.Activate before Application.MacroOptions
Hope this helps, please one-up the respective solution poster if their answer helped you 👍🏼
I understand that question is old, but will post my solution to this error, as it may be common and exception message is not informative.
I fixed it with passing a macro/UDF-holder workbook name into "Macro" parameter, like "'Workbook.xls(x/m/b)'!Macro/UDF_Name":
' Adding a macro from Personal.xlsb
Application.MacroOptions _
Macro:="'PERSONAL.xlsb'!Macro/UDF_Name", _
Description:="Description", _
ArgumentDescriptions:=ArgumentsDescription()
Another observation: if the Application.MacroOptions in being run from VBA add-in with ThisWorkbook.IsAddin = True e. g. from Workbook_AddinInstall or Workbook_AddinUninstall, and there is no other workbook opened, Excel throws error 1004. Problem can be solved if one calls ThisWorkbook.Activate before calling Application.MacroOptions.
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