How to GIve Format to the data in mshflexgrid?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dnb
    New Member
    • Jan 2008
    • 34

    How to GIve Format to the data in mshflexgrid?

    How to give format of data - " which are picked up from Access database through query" - in mshflexgrid in vb 6.0? I want to give currency format to the data. I used Format function in query but it does not work. So please give any idea for this. Thanks in advance.
    Last edited by Killer42; Jan 4 '08, 05:56 AM.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    that can be done directly by using sql statment

    try like this

    select id,name, '$.' ||salary as sal from employee

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Yes, but shouldn't Format function also work in SQL?

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Originally posted by Killer42
        Yes, but shouldn't Format function also work in SQL?
        Yes ,but you need to format the string before passing to SQL and processing or first fetch from sql and then format as per your requirment.

        Comment

        • QVeen72
          Recognized Expert Top Contributor
          • Oct 2006
          • 1445

          #5
          Hi,

          How you are populating the MSHFlexGrid..? Setting DataSource or Open Recordset and Loop Through and add row by row..?

          If using second method then, you can populate the textmatrix with the formatted String :
          [code=vb]
          Grd.TextMatrix( i, 2) = Format(RS("MyAm t"), "$#.##")
          [/code]

          If using First method, then
          After Binding to the datasource, Just loop through all the Rows and Format:
          [code=vb]
          Dim i As Long
          For i = 1 To Grd.Rows-1
          Grd.TextMatrix( i, 2) = Format(Val(Grd. TextMatrix(i ,2)) ,"$#.##")
          Next
          [/code]

          Regards
          Veena

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by debasisdas
            Yes ,but you need to format the string before passing to SQL and processing or first fetch from sql and then format as per your requirment.
            No, I mean can't you include Format() function in SQL? I thought Access SQL at least, had a Format function for just this kind of situation.

            Ok, I've just checked. Here's some SQL which I built in the Access Query Designer. It works, displaying the numeric field aaa as six digits.
            SELECT Format([aaa],"000000") AS Um FROM Table1;
            I entered the values 1, 2, 3 and 28000 in field aaa, then ran this query. Here's the output...
            Um
            000001
            000002
            000003
            028000

            Comment

            • QVeen72
              Recognized Expert Top Contributor
              • Oct 2006
              • 1445

              #7
              Hi,

              For Access Database, Directly Change the SQL Statement:

              "Select Field1,Format(A mtField,'##,### .00') As MyAmtField From MyTable"

              Regards
              Veena

              Comment

              Working...