I have the following code:
StrSheetName = "Weekly Account Balances"
StrTableName = "Account Weekly Balances"
fReportingFile = fDirectory & "\" & fReportingFile
DoCmd.SetWarnings True
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, StrTableName, _
fReportingFile, True, StrSheetName & "!"
I have verified that the sheet name, table names are correct and fReportingFile are correct using a break at the DoCmd.TransferSpreadsheet. I have also verified that 123 records are in the "Weekly Account Balances" sheet.
However, no records are transferred and I don't receive a warning.
I have also checked to see if there are any error tables created in the Access DB, but there are none.
Obviously, I have something wrong with the transfer call, but because I'm not getting any messages, I don't know what it is.
Why might I not be receiving any messages and no data is transferred?
Obviously, I have something wrong with the transfer call
No, that is correct, and it works - if, of course, your path and file names is pointing to an existing file, and you have specified the correct worksheet name.
So, double-check every parameter and your workbook.
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.
I trying to use two textboxes to perform a rename in VBA access.
Here is my code:
Private Sub Command61_Click()
Name Me.sourFullPath As Me.destFullPath
End Sub
Both sourFullPath and destFullPath have the whole file path include the folder path and the file name + extension, they all on the same drive.
But after I ran it, Access gives me
Run-time error 5: invalid procedure call or argument.
Does anyone know what causes that?
Thanks
The syntax is correct so check what you actually are trying to do:
Private Sub Command61_Click()
Debug.Print "Source: '" & Me.sourFullPath & "' Target: '" & Me.destFullPath & "'"
Name Me.sourFullPath As Me.destFullPath
End Sub
Also, the target folder must exist.
If you look into the error code it says on
https://msdn.microsoft.com/en-us/library/aa445484(v=vs.60).aspx
•An argument probably exceeds the range of permitted values.
If you extend the destination to over 255 characters then it does fail but with an error
Run-time error '53': File not found
It still could be that your source or destination path is to long.
I am having a most frustrating time time with the DoCmd.TransferSpreadsheet method. I have a workbook with multiple worksheets in which users are updating data and I have a script that puts all the records back into a single sheet, links the spreadsheet, and updates the data in my Access DB. My problem is in the Range parameter. I pass the following string and get the following error:
DoCmd.TransferSpreadsheet TransferType:=acLink, SpreadsheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:=linkSheet, fileName:=Wb.Path & "\" & Wb.name, _
HasFieldNames:=True, Range:="AccessUpdate!updateTable"
The Microsoft Access database engine could not find the object 'AccessUpdate$updateTable'. Make sure the object exists and that you spell its name and the path name correctly. If 'Access_Update$updateTable' is not a local object, check your network connection or contact the server administrator.
I can't seem to understand why it substitutes the dollar sign for the bang. Any other help in understanding how to specify the range would also be appreciated.
Thanks!
I know this is an year old question but it is an almost timeless problem.
I'm trying to do the same from the Excel side and bumping into the same problem. Access switching the sheet separator "!" for "$"
I found that this is a bug from Access 2000 that was never corrected. Or better, it was partially corrected at some point. So depending on your Access build and the size of the range [yes, size, since this is a bug from Access 2000] the solutions provided by Cisco or HansUp will work.
Another sources explaining the problem and a similar solution is provided by the MS$ themselves
https://answers.microsoft.com/en-us/office/forum/office_2007-access/transferspreadsheet-error-3011-can-not-file-sheet/980b2dc1-9ee1-4b3e-9c3c-a810f1428496
with the help of Bob Larson Former Access MVP (2008-2010) [see his very last post]
Now, if your range is on a different sheet with more than 65536 rows, this bug will come back.
See here for reference
Funny enough, if this is Sheet1 [yes, index 1 of all sheets] it will work with any range size. But any other sheet it wil fail.
This was my original range: BASE!A2:X68506, named REF_ACCESS. BASE is my Sheet5. Access 2010 & Excel 2010
I tried ActivateSheet, assign to string inside command, assign to string outside command, replace(,"$","!""), nothing worked. Even on Office 2016 from a friend
If I use "BASE!A2:X64506", it works. If I use "A2:X68506", Access assumes Sheet1 and works. Attention that all ranges do not have "$", but I guess you already know that
My last test was something like this monster
DoCmd.TransferSpreadsheet TransferType:=acImport, SpreadsheetType:=9, TableName:="TEST", Filename:=ThisWorkbook.FullName, HasFieldNames:=False, Range:=Worksheets("BASE").Name & "!" & Replace(Left(Worksheets("BASE").Range("REF_ACCESS").Address, Len(Worksheets("BASE").Range("REF_ACCESS").Address) - 1), "$", "")
A test that using my range within the 65536 row limit [6553 to be precise] would work. And it did.
So I see solutions with only two options for now. Either copy your range to Sheet1 or another sheet, as RyanM did, or divide your range in multiple DoCmd with 65536 rows.
I know it is long. Sorry, this was 2 full days looking for an answer without any real solution. I hope this helps other people with the same problem.
I tried multiple methods for getting around this without making major modifications to my code but with no avail. I did come up with a solution but it is rather resource intensive and messy. However, in case someone has a similar issue, I will post it here. I wound up separating my update sheet into it's own file from the rest of the workbook and linking that file. This prevented Access from trying to link a different sheet and got me around the whole Range issue. I know it's not elegant or efficient but it worked. If I figure out a cleaner way I'll post it here.
Set xl = Wb.Parent
xl.ScreenUpdating = False
xl.DisplayAlerts = False
strFile = mypath & "\TempIss.xlsx"
For i = 1 To Wb.Worksheets.count
If InStr(1, Wb.Worksheets(i).name, "Update", vbTextCompare) > 0 Then
tableId = i
Exit For
End If
Next i
If tableId = 0 Then
MsgBox "This workbook does not seem to have the necessary worksheet for updating " & _
"the Participant Issues Log in Access.", vbInformation, "Uh oh..."
Exit Function
Else
Set upWs = Wb.Worksheets(i)
upWs.Select
upWs.Copy
xl.ActiveSheet.SaveAs fileName:=strFile
xl.ActiveWorkbook.Close
Call rmSheet(Wb, "AccessUpdate")
xl.ScreenUpdating = True
linkSheet = "tempIssLog"
DoCmd.TransferSpreadsheet TransferType:=acImport, SpreadsheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:=linkSheet, fileName:=strFile, _
HasFieldNames:=True
Kill (strFile)
If the range is a named range (in Excel) follow the instruction above (HansUp comment).
If the range is defined in MS-Access be sure to pass a string (something like "A1:G12") and not the control name.
Dim StrRange as variant
Dim NameofMySheet as string
NameofMySheet = "xxxxxx" ' <- Put here the name of your Excel Sheet
StrRange = NameofMySheet & "!" & "A1:G12"
DoCmd.TransferSpreadsheet TransferType:=acLink, SpreadsheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:=linkSheet, fileName:=Wb.Path & "\" & Wb.name, _
HasFieldNames:=True, Range:= StrRange
Note 1: StrRange with no quotes!
I am a relative novice with Access and starting from scratch with coding, so be gentle.
I have an Access 2010 database with dozens of linked tables based on .txt files. Sometimes the database moves, the source files move or the file server just gets re-named. In these events I am looking for a simple way for a user of the database to remap and refresh the linked tables. Ideally, it would be user prompted, i.e. the user pushes a button to refresh from a navigation form or something. Then, the system prompts for the new folder location. The folder location would house all of the necessary files, so it only needs to be selected one time. Once selected, all linked tables should remap and refresh with the user getting an error or success message.
I have seen a lot of these questions asked, but they seem to be in older versions of Access or it is not asking for a user prompt or for a user to browse for the new path.
Thanks.
While I agree with Marc B that this seems like a very oddly constructed database you could use the following code the manually link the tables again to the proper location. You would need to work this into a system that can loop through all tables and do them all one by one or adjust this code to do that automatically. But you may want to just rethink your system.
Function SetTableLinkPath(strTableName As String, strTablePath As String)
If Nz(strTableName, "") <> "" And Nz(strTablePath, "") <> "" Then
Dim cdb As DAO.Database
Set cdb = CurrentDb
cdb.TableDefs(strTableName).Connect = ";DATABASE=" & strTablePath
cdb.TableDefs(strTableName).RefreshLink
MsgBox "Table link for " & strTableName & " has been successfully set to the path: " & strTablePath & "."
Else
MsgBox "You must enter a valid Table path and name!"
End If
End Function
I want to export record set "myTableRS" from Access 2010 into .xlsx file via VBA, but its showing the error as " The expression you entered is the wrong datatype for one of its argument". If I access any field value from the record set in msgbox using Msgbox(myTableRS![Field3]) so its working fine. Even when i export Access Table so the below code is working fine but not working for myTableRS record set.
I am using the code :
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, _
myTableRS, "D:\MAS.xlsx", True
Can anyone tell how to fix it?
How do I create a saved query? I have a table from which I want to search a particular record and save that particular record only at the same time of search in xlsx
If you look at TransferSpreadsheet, you will see that table name is a string.
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, _
"myTableRS", "D:\MAS.xlsx", True
This means that you cannot export a recordset using TransferSpreadsheet, however, you can create a saved query and export that.
Create a saved query
sSQL = "SELECT * FROM MyTable WHERE Id = " & thenumber
If Not IsNull(DLookup( _
"ExportQuery", "MSysObjects", "[Name]='ExportQuery' AND Type= 5")) Then
''Query exists, overwrite the sql permanently
CurrentDb.QueryDefs("ExportQuery").SQL = sSQL
Else
CurrentDb.CreateQueryDef "ExportQuery", sSQL
End If