Using a function in form

tblues87

Registered User.
Local time
Today, 09:28
Joined
Apr 7, 2011
Messages
22
Hi

Can someone help me with functions. I'm just starting to learn how to use vba with access.

I wrote simple function that calculates difference of two fields:

Code:
Public Function oduzimanje(IznosPlaćanja As Double, CijenaTečaja As Double) As Double
oduzimanje = (CijenaTečaja - IznosPlaćanja)
End Function
In form in which I would like to use this function , I made Text box and in it wrote

Code:
=oduzimanje([Iznos plaćanja];[Cijena tečaja])
And when I switch to Form view in that text box instead of result I get

Code:
#Name?
Thanks
 

Attachments

  • slika5.jpg
    slika5.jpg
    98.1 KB · Views: 117
Make sure that you change the name of the controls for

[Iznos plaćanja] And [Cijena tečaja]

So change the names of the text boxes to

txtIznosPlaćanja
txtCijenaTečaja

And then keep the names you had in the function call:
Code:
=oduzimanje([Iznos plaćanja];[Cijena tečaja])
 
Thanks for answer.

I changed the names of the controls as you said in property sheet and still the same.
You can see it in picture
 

Attachments

  • slika7.jpg
    slika7.jpg
    100.1 KB · Views: 112
Thanks for answer.

I changed the names of the controls as you said in property sheet and still the same.

Did you make sure that the function call didn't change the names as well? If you have Name Auto Correct on (which is the default) then if you changed the names on the form then it also would have changed this:

=oduzimanje([Iznos plaćanja];[Cijena tečaja])

to this

=oduzimanje(txt[IznosPlaćanja];[txtCijenaTečaja])

but you don't want that. You want the field names

=oduzimanje([Iznos plaćanja];[Cijena tečaja])

so go check to see if that happened and if it did correct it.
 
I checked they didn't change.

=oduzimanje([Iznos plaćanja];[Cijena tečaja])

I uploaded that test DB can you please take a look if you have some time

Thank you very much
 

Attachments

Okay, I think I see your problem. You can't name the module the same name as the function. So, rename the module to basOduzimanje and then it should work. However, the database you have sent is corrupt. It has a module for a form named frmPlacanje but there is no form in there named that. And I tried to import everything into a brand new database shell and it would not import your plaćanje form.

So, I think you need to start fresh.
 

Users who are viewing this thread

Back
Top Bottom