Undesired Rounding...

kdm3

Registered User.
Local time
Today, 01:49
Joined
Aug 2, 2004
Messages
43
Hi a problem has been perplexing me...

I am mitgrating some data, and forgot to include one of the fields. Hence I wrote a little function to add the relevant field values on, easy enough - or so I thought.

I am appending the weights of some items on, and the data type is DOUBLE, with a variable number of decimal places. I wrote this sub in fact for this purpose:

Sub addweight()

Dim dbs As DAO.Database
Dim rsthprc As DAO.Recordset
Dim rstcase As DAO.Recordset

Set dbs = CurrentDb
Set rsthprc = dbs.OpenRecordset("query2", dbOpenDynaset)
Set rstcase = dbs.OpenRecordset("casemodel", dbOpenDynaset)

rsthprc.MoveFirst

Do While rsthprc.EOF = False

rstcase.FindFirst "model = '" & rsthprc!model & "'"

Do Until rstcase.NoMatch = True

With rstcase
.Edit
!Weight = rstcase!Weight
.Update
End With
Debug.Print rsthprc!Weight
Debug.Print rstcase!Weight
rstcase.FindNext "model = '" & rsthprc!model & "'"

Loop

rsthprc.MoveNext

Loop

End Sub

It works OK, but keeps rounding the weight (inserted into the casemodel table) up to an integer value, even though the data type of both tables is DOUBLE. Any ideas how I can ensure that the decimal places are retained?

Thank You kindly.
 
CDbl function around the rstsource("field") eg
Code:
rstDest("field")=cdbl(nz(rstsource("field"),0)
NZ only needed if there is likely to be a null in the field.


Possibly you could use an Sql update or insert into linked on a common id.

Vince
 
Last edited:
Why not just use an Update query? and please don't double post
 
I already deleted the post from this forum as it was a duplication of the one in the Modules and VBA forum. :mad:

I'll delete that one instead.
 

Users who are viewing this thread

Back
Top Bottom