Get values from fields in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
how i can get the values from the fields in the form? i did the form in
access. and then calculate the value to the total field?
any Help?
 
Bruno said:
how i can get the values from the fields in the form? i did the form in
access. and then calculate the value to the total field?


As long as a field is included in the form's record source
table/query, you can just refer to it using the form object.
If the code is in the form's module, you can just use:
Me.fieldname

The same is true if you are using the word "field"
incorrectly when you really mean to use the word "control":
Me.controlname

I have no idea what you mean by "calculate the value to the
total field", but, normally, you should not save a
calculated value to a field in a table.
 
Hi,
i'm not understanding very well, but i will send my function and then maybe
you can help me, if you want:

Function primeiroano()
Dim x, y, t
Dim anoa As Long
Dim adaqui As String
Dim dias As String
Dim perc As String
Dim vcomp As String

Set anoa = Form_Inventário.Tanoactual.Value
Set adaqui = Form_Inventário.Tanodataaquisicao.Value
Set dias = Form_Inventário.Tcaixadias.Value
Set perc = Form_Inventário.Tpercentagem.Value
Set vcomp = Form_Inventário.Tvalorcompra.Value
Set t = Form_Inventário.T1ano.Value

If anoa = adaqui Then
x = (dias / 365)
y = (perc * vcomp)
t = x * y
Else
t = "0"
End If

End Function

The name of the fields are in portuguese, os don't worry because of the
names, if ou don't understand. the question is the same i put before. how can
i get the values from the fields and calculate them and set in the T1ano
field (= vairant t)
thanks, for any help.

"Marshall Barton" escreveu:
 
Bruno said:
i'm not understanding very well, but i will send my function and then maybe
you can help me, if you want:

Function primeiroano()
Dim x, y, t
Dim anoa As Long
Dim adaqui As String
Dim dias As String
Dim perc As String
Dim vcomp As String

Set anoa = Form_Inventário.Tanoactual.Value
Set adaqui = Form_Inventário.Tanodataaquisicao.Value
Set dias = Form_Inventário.Tcaixadias.Value
Set perc = Form_Inventário.Tpercentagem.Value
Set vcomp = Form_Inventário.Tvalorcompra.Value
Set t = Form_Inventário.T1ano.Value

If anoa = adaqui Then
x = (dias / 365)
y = (perc * vcomp)
t = x * y
Else
t = "0"
End If

End Function

The name of the fields are in portuguese, os don't worry because of the
names, if ou don't understand. the question is the same i put before. how can
i get the values from the fields and calculate them and set in the T1ano
field (= vairant t)


I'm not understanding very well either.

It appears that you are getting the values from the
**controls** on the form.

There are two problems I can see in the function's code.
One is that you should not be returning a string when anoa
does not equal adaqui. That line should be:
t = 0

The other is that the function never sets its return value.
I think you want the line:
primeiroano = t
before the End Function line.

Once you have the function working properly, you can use it
to display the calculated result in a text box on the form
by using a control source expression like:
=primeiroano()
 
Back
Top