operation in data...

mfuada

Registered User.
Local time
Today, 20:21
Joined
Feb 4, 2009
Messages
63
Hi
this is my script :

Private Sub Command45_Click()
tot_valtxt.Value = currency_ratetxt.Value * Listbox12.Value
End Sub


if i click the button, the textbox tot_valtxt.Value is blank...
the listbox12.value is a listbox with a row source from a query.
So what i would like to do is to add a query and data in the textbox form...
and i've changed all the format to currency including data in the table...
could anybody help?

thx

 
try this

Private Sub Command45_Click()
tot_valtxt.Value = val(currency_ratetxt.Value) * val(Listbox12.Value)
End Sub
 
nope it's not working, i got a message "invalid use of null".....
 
Try:
Code:
[COLOR="Navy"]Private Sub[/COLOR] Command45_Click()
    tot_valtxt.Value = Nz(currency_ratetxt.Value, 0) * Nz(Listbox12.Value, 0)
[COLOR="Navy"]End Sub[/COLOR]
 
Works perfectly... thank you.. btw could you tell me whyis my code doesn't working, so i can learn from my mistake?
 
Works perfectly... thank you.. btw could you tell me whyis my code doesn't working, so i can learn from my mistake?

You needed to use the NZ function to deal with NULL values as you can't multiply a null to get an answer. So, you would get the "invalid use of null" error. Using the NZ function, as he had written it, substitutes a zero (0) in place if there is a null.
 
sorry guys.. but after i restarted my project the tot_valtxt.value return with "0" value...
i assumed that because access did not read value of listbox12 because the listbox12 has the value from row source that originally came from a query...
so is there any suggestion?

ps:it works fine when i first tried the NZ function:(
 
You say that the code provided is failing, but maybe that's because the user hasn't selected a row of the listbox as yet?

Has the user selected a row, or not? If not, the calculation will fail.
 

Users who are viewing this thread

Back
Top Bottom