I'm trying to export a query as a .csv but the query has parameters. I can get the query to run but when I try to export it I get the error:
"Runtime Error 3828
Cannot reference a table with a multi valued field using an IN clause that refers to another database"
Private Sub EthosRpt_Click()
DoCmd.OpenQuery "EthosSessions"
DoCmd.TransferText acExportDelim, , "EthosSessions", "C:\[file path]\test.csv"
End Sub
Not sure how to fix this. Any help?
MLibby was right.
Make Table query fixed the whole issue.
Related
I'm having a lot of trouble trying to export a table (actually a query, but I made it create this table just to see if something changed) to a .csv file, I was using this line to make it:
DoCmd.TransferSpreadsheet acExport, , "TABLE", "TEST.csv", False
But it gives me error 3027 (something about read-only database or object), but I created this table, and as far as I'm concerned, it is possible to write on it!
Then I tried using this line here:
DoCmd.OutputTo acOutputTable, "TABLE", acFormatTXT, "test.csv"
And it works just fine. But When I came to see the results, they came with a table drawn around my data, and it's just horrible!
Anyways, it doesn't matter really which command I want, I'd appreciate any help as long as it works. Thanks!
TransferSpreadsheet is for spreadsheet files. Try:
DoCmd.TransferText acExportDelim, , "TABLE", "d:\path\TEST.csv", False
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 am trying to create a macro to update the value of a field in a form based off the results of a query.
I am entirely new to working with vba in Access so I apologize if I am asking a basic question.
I should mention, the "test" query returns exactly one result. It is essentially used similarly to a VLookup.
Currently My code is thus:
Private Sub UpdateBasic_Click()
Dim bucket As String
DoCmd.OpenQuery "test", acViewNormal, acReadOnly
'this line is meant to record the result of the query into a variable. It is not working but I haven’t found the right command to get it to pick up the data yet.
bucket = A1
DoCmd.Close acQuery, "test", acSaveNo
DoCmd.OpenForm "BasicData", acNormal, , , acFormEdit, acWindowNormal, "Global_ID = 'sdkfa'"
'this line is meant to update the value of the field on the form.
DoCmd.SetProperty testfield, acPropertyValue, bucket
End Sub
I am having no luck getting the SetProperty command to work at all. It is consistently telling me I have a data type mismatch regardless of whether I try to give it a variable like bucket or a value like 10. Error message is as follows:
Run-time error ‘2948’:
An Expression you entered is the wrong data type for one of the arguments.
Any and all help would be appreciated.
If you're simply trying to assign the result of a query to the value of a field in a form, I'd recommend a DLookup() function. You can use it like this (assuming the form's control is a textbox):
Me.TextBox.Value = DLookup("FieldName", "QueryName")
More elaborate solutions would involve recordsets, etc. but if you're looking for a quick, simple solution this should do just fine. Hope that helps!
I am transferring from text files to access DB table using DoCmd.TransferText. Just that for each record created in my access DB table, apart from the text file lines, i would like to add one more field to each record, but for DoCmd it seems to be a constraint. Is there any way i can do that?
You can import the text file into a staging table then
run a make table query or Append Table Query into your finished table. In the query add the needed field(s) via calculation in the Query Design:
Myfield:Null or MyField:IIF(SomeOtherField="M", ...) etc. Then save the query.
In your VBA (Assuming that "StagingTable is where you import the file and
AppendStagingTableToWorkTable is your appendquery:
DoCmd.TransferText acImportFixed, "My Import Spec", "StagingTable", _
"C:\TextFile.txt", False
DoCmd.OpenQuery "AppendStagingTableToWorkTable"
All -
I'm embarrassed to ask something that appears to be so rudimentary, but I'm stuck.
Using Access 2007, I ran a query against a single 84K row table to produce a result set of ~80K row. I can't copy/paste the result set into Excel (Access fails copy/pasting > 64K rows). When I right-click on the query and export, no matter what format I try, it only exports the first row (ID).
How can I get Access to export the entire result set? (I've tried highlighting everything, etc. I also tried using the 'External Data' ribbon, but that just exports the original table, not the result set from the query I ran.)
Thanks!
I ran a query, highlighted everything by clicking on the little arrow in the upper left, CTRL-C, opened Excel, CTRL-V. Exported the whole thing. (Granted I didn't have ~100k rows like you, but I don't understand why it wouldn't handle that too.)
Or is that not what you want?
What if you copy 40,000 rows at a time to different tabs in your Excel file?
I have had a similar problem with Access 2013, so decided to share how to resolve it. The only way I could solve this issue was by using VBA.
Only update testSQL (easy to see when you go to SQL view of your query) and CSV_file_path (the file path of your CSV export)
Sub Export_ToCSV()
Dim testSQL As String
Dim UserInput As String
Dim db As Database, qd As DAO.QueryDef
Set db = CurrentDb
testSQL = "SELECT Table1.Column1, Table1.Column2, Table1.Column3 FROM Table1;"
CSV_file_path = "C:\temp\filename.csv"
Set qd = db.CreateQueryDef("tmpExport", testSQL)
DoCmd.TransferText acExportDelim, , "tmpExport", CSV_file_path, True
db.QueryDefs.Delete "tmpExport"
MsgBox ("Finished")
End Sub