Need to keep text format when retrieving records from database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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 Format>Cells>Number to change the format after extracting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top