Access Query Export to Excel with formatting - ms-access

My invoice number (Auto number) formatted like “Binu/21-22/”0000. While running the query, invoice number is showing “Binu/21-22/0001” which exactly I want When I am exporting it to excel with following VBA code -DoCmd.OutputTo acOutputQuery, "Qry_Test", acFormatXLSX, sFileName, True- that time also excel file is showing the format “Binu/21-22/0001” but when I am clicking on the invoice number on excel file cell then its showing only “1”. I want excel file also with the correct format “Binu/21-22/0001” instead of “1”. Anyone can help me how to resolve this”

I am assuming you are using format option to display invoice number as "Binu/21-22/"0000. So when it is exporting to excel then it is exporting with format not as value. So, you can write you query with FORMAT() function which will display as your desired format and export to excel will export as value. Try-
SELECT "Binu/21-22/" & FORMAT(MyTable.[InvoiceNo],0000) as [InvoiceNo] FROM MyTable
Save this query and then export to excel. Add your other fields in the query. as required.

Related

How to Keep SQL Formatting of Date and Quotes in Excel CSV?

I'm trying to update a massive SQL table with thousands of rows and the best method I've come up with is a script that allows me to import a CSV file.
My problem is that after I export the original CSV file from the SQL and then edit it in Excel to add new values, it removes the quotations around all the values. (which I can see when opening the CSV in a TXT editor)
I found a solution on here using visual basic in Excel and the formula:
for each v in range("A1:A1000") : v.value = CHR(34) & v.value & CHR(34) : next
The problem is that this formula auto-formats my date fields... so I'll be left with "8/20/2018 20:21:02 AM" when I need to have the dates in the standard SQL format: 2018-08-20 20:21:02.
Your problem is the way you open the file in excel
To open it properly, go to the data ribbon, choose import from text and on the wizard, make sure that the data type for the column is text
Another way to handle the issue is by a formula, on the converted datetime in excel format:
TEXT(cell-address, "yyyy-mm-dd hh:mm:ss")

ssrs 2008 r2 export to csv displays column all the time

In an SSRS 2008 R2 report, the users are going to export the data to: csv (comma delimited) and excel.
I am using the following to display if a column is visible or not:
=IIF(Mid(Globals!RenderFormat.Name,1,5)="EXCEL" AND First(Len(Fields!CustomerNumber.Value)) > 0,False,true)
I have set the DataElementOutput=Output for the textbox that displays the value.
I have left DataElementOutput=Auto for the textbox that contains the column header.
When exporting to csv (comma delimited) or excel, I basically want the column to be visible when there is data in the field and the column not to be visible when there is no data.
The code works for excel but the code does not work for comma delimited.
Thus, can you tell me what I can do so the column is not disaplyed when the data is exported to csv (comma delimited)?
You may attempt to do this with a continuation of statement accounting for the "CSV" output type.
=IIF( (Mid(Globals!RenderFormat.Name,1,5)="EXCEL" OR Mid(Globals!RenderFormat.Name,1,5)="CSV") AND First(Len(Fields!CustomerNumber.Value)) > 0,False,true)
Or a switch statement:
=Switch(Mid(Globals!RenderFormat.Name,1,5)="EXCEL" AND First(Len(Fields!CustomerNumber.Value)) > 0,False, Mid(Globals!RenderFormat.Name,1,5)="CSV" AND First(Len(Fields!CustomerNumber.Value)) > 0,False,true)
However....
The problem may be due to the nature of a csv file being a simpler format that cannot handle this in output. It depends on how SSRS handles the output if it is hard writing the output before the write operation. It may simply not work because of the limitations of the format of CSV. If this was the case you may be able to simple take the Excel output and save it to CSV either in code or a manual operation.

MS Access: Command button to export a report to a CSV file

I was wondering if this was possible. I have my main form with a bunch of tables on it, and then I have a report. Standard stuff there. The report is named Report1. What I was wondering, is there a way I can put a command button on my main form, that when pressed, will export Report1 onto my desktop (or wherever I specify) in a CSV format? I would like to do this in VBA if possible. I'm not sure if I could make a macro format into CSV, but I am pretty open to any suggestions. Thank you
You can export the report's data to CSV by using DoCmd.TransferText with the report's Record Source table or named query.
Take a look at this: VBA DoCmd.TransferText - exporting query to .csv with user defined file path
A report is always based on a query.
You can find your query in the properties within the Design View of your report ("RecordSource").
The best way should be to generate a query (based on your current report) and link that query to the report ("RecordSource") and to the export button (DoCmd.TransferText).
Thereby, if you want to change your report / report data, you only need to change it once.

MS Excel : How to get the changed date format when exporting as csv?

I have a MS Excel file in which a column contains date in the format m/d/yyyy and mm/dd/yyyy. I wanted all these dates to be imported in to a MySQL table.
So in MS Excel, I changed the cell format to custom date 'yyyy-mm-dd' and everything looked fine in the excel columns. When I exported it as .csv, all dates were in the original format i.e., m/d/yyyy and mm/dd/yyyy but not as 'yyyy-mm-dd'.
Please help me in this regard. Thank you!
Like David mentioned, you may have to replace the text before importing it to the MySQL table. You can try this formula:
=TEXT(A2,"yyyy-mm-dd")
And copy down. Then do a copy->Paste Values into the original date column. Then delete the temporary column with the Text() formula.
Try importing it after you replace the text. It should work out.

Numbers not keeping format when exported from SSRS 2008 R2 to Excel 2010

I am using an expression to display currency depending on if the value is in the millions or in the thousands. This expression is set in the Format property of my report:
=iif((Fields!PrevActual.Value < 100000), "'$'#,,0,'K';('$'#,0,'K')", "'$'0,,.0,'M';('$'0,,.0,'M')'")
In this way, if the value is 1,500,000 the number will display as $1.5M and if it's 15,000 it will display as $15k.
The problem is when I export the file to Excel. The numbers in the thousands retain the formatting, but the numbers in the millions lose it. So I have a spreadsheet with numbers like 1,500,000 and $15k. All numbers are exporting as text.
Does anyone know of a way to keep the formatting in excel so it matches how it's displayed on the SSRS report while making sure it's also still a number?
Essentially, I want to mimic what excel was doing before we automated this report with SSRS. Numbers in the millions were in this custom number format: $#.0,,\M and thousands were in this one: $#,K.
Thanks!
If you export the excel formula then it can work. i.e. export
="text(1500000," ""'$'0,,.0,'M';('$'0,,.0,'M')"")"
Excel will then convert the formula to the final formatted value
$15M
The tricky part is making the format string valid in excel, and creating an SSRS formula which will concatenate strings and generate an Excel formula.
This can help:
http://msdn.microsoft.com/en-us/library/ms159220%28SQL.90%29.aspx