Results 1 to 4 of 4

Thread: Format numbers when executing sql

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    64

    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?

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    64

    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.

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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
  •  



Click Here to Expand Forum to Full Width