convert text to number in VBA

G

gizzy

what function in VBA should I use to convert string field to a currency
or any numeric format?
I have a database that gets data from SQL server and all the values
there are stored in a character format, but i need to do some
mathematic functions on Access so i need numeric format

thanks in advance,
Gizzy
 
G

Guest

try

Int([FieldName])

Some of the functions you can check
Clng = Convert to Long
CDbl = Convert to Double
CCur = Convert to Currency
 
G

gizzy

Thank you!

But what if i leave one of the fields blank?
if i use CCur(field2) then i get message "invalid use of null"
 
M

MH

If you want to ignore nulls and return zeros where the text value is null,
use:

CCur(Nz([FieldName]))

MH
 
J

John Spencer

One method.

IIf(IsNumeric([FieldName]),Val([FieldName]),Null)
If you want to ignore nulls and return zeros where the text value is null,
use:

CCur(Nz([FieldName]))

MH

gizzy said:
Thank you!

But what if i leave one of the fields blank?
if i use CCur(field2) then i get message "invalid use of null"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top