|
-
Oct 19th, 2010, 03:31 PM
#1
Thread Starter
Lively Member
Format numbers when executing sql
Greetings. I am using VB6 to retrieve data from some foxpro tables as follows.
Dim cnCompany As New ADODB.Connection
Dim RsExport As ADODB.Recordset
strSQL = "Select price from Products"
Set RsExport = cnCompany.Execute(strSQL)
This works fine, but I would like to format the price. I have tried various including...
strSQL = "Select format(price,'0.00') from Products"
Set RsExport = cnCompany.Execute(strSQL)
but it gives the error message
format.prg does not exist
Does anyone know what will work with ADODB?
-
Oct 19th, 2010, 03:49 PM
#2
Re: Format numbers when executing sql
The Format is only appropriate when you wish to display the value.
Code:
strSQL = "Select price from Products"
Set RsExport = cnCompany.Execute(strSQL)
Debug.Print Format(RsExport![price],"##0.##")
would print the value formatted.
-
Oct 19th, 2010, 05:18 PM
#3
Thread Starter
Lively Member
Re: Format numbers when executing sql
No good to me sorry. My next line
wksReport.Range("A2").CopyFromRecordset RsExport
populates an excel spreadsheet with whatever data is in the recordset, so need to format it in the selection. The Format command used to work with a foxpro recordset, but I needed to change to ADODB and it seems that format does not work with it.
-
Oct 20th, 2010, 01:16 AM
#4
Re: Format numbers when executing sql
The only thing I can suggest is to format the target Cell Range in Excel. I'm no expert but something like
Code:
wksReport.Range("A2").NumberFormat = "##0.##"
might work.
(If it doesn't, then I suggest you google 'Excel NumberFormat' and see if you can come upon some examples.)
Last edited by Doogle; Oct 20th, 2010 at 01:21 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|