D
dile
I am trying to use a recordset to copy the value in a Decimal type
field from a "temporary" table to a Decimal type field in a "permanent"
table, using VBA. I have to import records from Excel which might
include duplicates of records already in the table, and need to check
that the record is not a duplicate before I insert it into the
permanent table.
I need later calculations to be precise (it is a financial
application), and need to not have rounding errors, so am using the
Decimal type in the table fields.
When I run my "insert into" SQL statement, I get the error message
"Run-time error '13': Type Mismatch".
My abbreviated code is:
Dim dblAmount As Variant
Dim curAmount As Currency
Dim sqlInsert, sqlInsertFlds As String
' get variables from recordset
dblAmount = rstTemp.Fields("Amount")
curAmount = CCur(dblAmount)
sqlInsertFlds = "Amount"
sqlInsert = "INSERT INTO ImportVouchers (" + sqlInsertFlds + ")
VALUES (" + dblAmount + ")"
' run the insert statement
DoCmd.RunSQL (sqlInsert)
I have tried to convert the variant variable to currency using
CCur(dblAmount), inserting the currency variable curAmount (both as
above and getting its value directly from the recordset field), and to
insert the value as a variant; none of these have worked.
Does anyone have any advice?
Thanks.
field from a "temporary" table to a Decimal type field in a "permanent"
table, using VBA. I have to import records from Excel which might
include duplicates of records already in the table, and need to check
that the record is not a duplicate before I insert it into the
permanent table.
I need later calculations to be precise (it is a financial
application), and need to not have rounding errors, so am using the
Decimal type in the table fields.
When I run my "insert into" SQL statement, I get the error message
"Run-time error '13': Type Mismatch".
My abbreviated code is:
Dim dblAmount As Variant
Dim curAmount As Currency
Dim sqlInsert, sqlInsertFlds As String
' get variables from recordset
dblAmount = rstTemp.Fields("Amount")
curAmount = CCur(dblAmount)
sqlInsertFlds = "Amount"
sqlInsert = "INSERT INTO ImportVouchers (" + sqlInsertFlds + ")
VALUES (" + dblAmount + ")"
' run the insert statement
DoCmd.RunSQL (sqlInsert)
I have tried to convert the variant variable to currency using
CCur(dblAmount), inserting the currency variable curAmount (both as
above and getting its value directly from the recordset field), and to
insert the value as a variant; none of these have worked.
Does anyone have any advice?
Thanks.