473,382 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

changing of text format to number format when data is extracted from access to excel

3
hello .. hmm currently i'm working on vba in excel, apparently i use ADO to extract a table data from access to excel and it works fine. the problem is when i use the extracted data to create a chart using vba and it doesn't seem to display the data properly.. it is due to the text format when the data is extracted to excel..
how can i change it to number format when the table of data is extracted ..

Here's the code:

Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim stDB As String
Dim wssheet As Worksheet
Dim lnNumberOfField As Long, lnCount As Integer
Dim Target As Range
Dim Worksheet As Worksheet

Set wssheet = ThisWorkbook.Worksheets("SMS")
'wsSheet.Name = "Download"
'Application.DoubleClick
'Worksheet.Sheets("SMS").Width = 10
stDB = ThisWorkbook.path & "\" & "GSM_All.mdb"

wssheet.Range("A1").CurrentRegion.clear

cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & stDB & ";"

rst.Open "SELECT * FROM Sms", cnt

lnNumberOfField = rst.Fields.Count

For lnCount = 0 To lnNumberOfField - 1
wssheet.Cells(1, lnCount + 1).Value = rst.Fields(lnCount).Name
Next lnCount

wssheet.Cells(2, 1).CopyFromRecordset rst
Sheets("SMS").Activate
'Worksheets("SMS").Visible = True


Set rst = Nothing
Set cnt = Nothing

Application.ScreenUpdating = True
Oct 28 '08 #1
6 8972
Hi

What I did (it might not suit you 100%) I used ADO to transfer the data to the spreadsheet and in the spreadsheet I have cells which refer to the ADO results but conver them to number.

like

=VALUE(B9)


Regards
Emil
Oct 28 '08 #2
Stewart Ross
2,545 Expert Mod 2GB
Hi. The Excel recordset transfer function CopyFromRecordSet does not of itself convert numbers to text - it has much the same effect as simply copying the underlying query manually and pasting the data into Excel. The default format of the cells in an Excel sheet is the General format and numbers are interpreted as numbers wherever possible. CopyFromRecordset simply pours the data into the cells using whatever format is already set.

Check the underlying query or table itself and to see if any processing has been applied that has converted the values, such as the use of Format (a function that actually returns a string value, not a number). You can tell immediately from the alignment of the values if you open the query (or table) concerned; if the numbers are left-aligned instead of right-aligned the values are text strings, not numbers at all.

-Stewart
Oct 28 '08 #3
and1
3
Hi emsik1001.. thanks for responding... hmm do i have to apply =value(B9) in the spreadsheet itself or ? I'm pretty new to excel vba .. hmm is there any alternative way for me to change the format ?
Thanks Stewart Ross Inverness for your advice, i'll look into it ..
hmm thanks for your help .. :D
Oct 29 '08 #4
Hi

The quickest way (for me) would be to put extra column against your row results and put =value(A:A) where A:A is the column of your original numbers.

and then use the extra column.

Hope it helps
Emil
Oct 29 '08 #5
if you want...you can then copy // paste special (values) this should become number. (this way you can overwrite your original data with number format.

Regards
Emil
Oct 29 '08 #6
and1
3
hey Emil .. i took your advice and tried .. well i copied and paste it as special and it works .. i didnt know it was that easy .. haha .. well you've been a great help .. i really appreciate it .. thanks a lot for your advice .. :D
Oct 30 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ralph | last post by:
I'm trying to import a range of cells from an Excel spreadsheet into a table in access. The first row contains column labels, but I cannot use those as my field names, both because of their format...
5
by: Macca | last post by:
Hi, I have a table which has a date/time field. I am storing them as follows :- 01/01/2005 11:25 01/01/2005 19:44 02/01/2005 05:04
1
by: kim | last post by:
Hello! Here, in brief, is my problem. Access 2002. I need to export to a csv text file with text delimiters on every field. I find that if I save the original data in Excel and make sure the...
8
by: John Brock | last post by:
I am creating an Excel workbook using VB.NET, and have run into a problem. Excel at times insists on reformatting data that I enter into cells, e.g., converting "01234" to "1234", and this screws...
9
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to...
1
by: michaelw118 | last post by:
Hi, I hope someone can give me some solutions to these problems I faced. I imported some data to Excel. Then in Access, I table-linked to this file. I have two fields which in Excel is in...
1
by: chrspta | last post by:
I am new to Visual basic. I need a program using VB6 that converts txt files to excel file.Description is in the below: The form should have the Drive list, Dir list, file list and cmdConvert...
1
by: Brian | last post by:
Hello, I am new to Microsoft access 2007 and I have created a new database. There is a dollar about that I have to change from text to currency format. Also, there is a zip code that I have to...
7
by: franc sutherland | last post by:
Hi everyone, I am using Access 2003. I have a database with a table in it which is linked to an excel spreadsheet. When I install the database on someone else's system, the pathname to the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.