Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adodb adDecimal help

Status
Not open for further replies.

TimRHSD

Programmer
Apr 18, 2002
35
0
0
US
Currently, I am putting data into an adodb.recordset. I am using a field which needs to be decimal, but everytime I use it, the right side of the decimal is '00'. e.g. 15.35 comes in as 15.00. I have spent hours trying to find an example for this. I know I need to set NumericScale somehow, but can't find an example. My guesses have failed thus far.

Thanks,

Tim

Tim Rutherford
 
Something like this ?
With rs.Fields("NameOfField")
.Type = 14 ' adDecimal
.Precision = 16
.NumericScale = 2
End With

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PH,

I added your code and here is my code and I am getting error,"Operation is not allowed when the object is open" (same error I was getting before)

Code:
' 		Create the RecordSet objects.
    	Set rst = CreateObject("ADODB.Recordset")
' 		This Recordset will hold the Distribution information
'		Need to fix Amt rounding issue 6/4/04 TSR
    	rst.CursorLocation = adUseClient
    		rst.Fields.Append "Amt", adDecimal
    		rst.Fields.Append "CDH", adInteger
    		rst.Fields.Append "Date", adDate
    		rst.Fields.Append "Dept", adChar,4
        	rst.Fields.Append "EmpID", adChar, 7
        	rst.Fields.Append "EmpName", adChar, 30
        	rst.Fields.Append "GLObj", adchar,4
   			rst.Fields.Append "Hours", adVariant
   			rst.Fields.Append "Obj_SB",adChar,4
        	rst.Fields.Append "Period", adChar,7
        	rst.Fields.Append "Location",adChar,3
        	rst.Fields.Append "Fund",adChar,3
    	rst.Open
    	With rst.Fields("Amt")
    		.Type = 14
    		.Precision = 16
    		.NumericScale = 2
    	End With

Tim Rutherford
 
Have you tried this ?
rst.Fields.Update
With rst.Fields("Amt")
.Precision = 16
.NumericScale = 2
End With


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Just don't open it?

This works fine (dropped a few fields in this version):
Code:
'         Create the RecordSet objects.
        Set rst = CreateObject("ADODB.Recordset")
'         This Recordset will hold the Distribution information
'        Need to fix Amt rounding issue 6/4/04 TSR
        rst.CursorLocation = adUseClient
            rst.Fields.Append "Amt", adDecimal
            rst.Fields.Append "CDH", adInteger
            rst.Fields.Append "Date", adDate
            rst.Fields.Append "Dept", adChar, 4
        With rst.Fields.Item("Amt")
            .Precision = 16
            .NumericScale = 2
        End With

        'Add some data, extract it.
        rst.Open
        Dim aryFNames
        aryFNames = Array("Amt", "CDH", "Date", "Dept")
        rst.AddNew aryFNames, Array(34.95, 12, #March 11, 2004#, "FUDD")
        rst.AddNew aryFNames, Array(12.37, 7, #April 21, 2003#, "DUDD")

        rst.MoveFirst
        MsgBox rst.GetString(adClipString, , ", ", vbNewLine)
        rst.Close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top