ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need to keep text format when retrieving records from database (https://www.excelbanter.com/excel-programming/324715-need-keep-text-format-when-retrieving-records-database.html)

Markantesp

Need to keep text format when retrieving records from database
 
I'm importing records from an access database to excel using ADO. When the
records are stored in the excel sheet, the format has changed. How do I keep
it to a text format. For example, record 9900000000000080 has changed from
text to general and now looks like 9.9E+15.

gocush[_29_]

Need to keep text format when retrieving records from database
 
When I use ADO to extract from Access to xl I use the following code to
format several columns:

The variable "ExtractFields" is the xl Named Range of Field Names ( at the
top of each col of the extract range)

Dim Field As ADODB.Field
Dim k as interger

k = 1
For Each Field In rs.Fields
If Field.Type = adDate Then
ExtractFields(k).EntireColumn.NumberFormat = "mm/dd/yy"
ElseIf Field.Name Like "Age" Then
ExtractFields(k).EntireColumn.NumberFormat = "00"
ExtractFields(k).EntireColumn.HorizontalAlignment = xlCenter
End If
k = k + 1
Next Field

You should be able to adapt the above to your situation, changing to
whatever format you want for the desired field. Or just manually select the
column and select FormatCellsNumber to change the format after extracting.


"Markantesp" wrote:

I'm importing records from an access database to excel using ADO. When the
records are stored in the excel sheet, the format has changed. How do I keep
it to a text format. For example, record 9900000000000080 has changed from
text to general and now looks like 9.9E+15.



All times are GMT +1. The time now is 05:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com