dbTalk Databases Forums  

How to calculate form field

comp.databases.ms-access comp.databases.ms-access


Discuss How to calculate form field in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Lanka Danweem
 
Posts: n/a

Default Re: How to calculate form field - 08-13-2011 , 07:21 AM






On Aug 12, 9:36*pm, Patrick Finucane <patrickfinucan... (AT) gmail (DOT) com>
wrote:
Quote:
On Aug 12, 1:36*am, Lanka Danweem <m... (AT) lankadanweempituwa (DOT) com> wrote:





On Aug 11, 11:15*pm, Patrick Finucane <patrickfinucan... (AT) gmail (DOT) com
wrote:

On Aug 11, 2:05*am, Lanka Danweem <m... (AT) lankadanweempituwa (DOT) com> wrote:

How to calculate form field

Please any body know how to design a form with calculation on a field.
How can I format the table field to get result of form field.

Acturaly what I want is , when I ender numeric data to form field e..g
I want to sum 5 data (125.50+200+100+45+75) for one field without
calculate separately
Are there any format to enter these as excel cell to get result *of
545.50?.

Like this

= 125.50+200+100+45+75)

You can create a text box on a form. *If you open the property sheet
up for the text box and give it a name of Sumit by pressing on the
Other tab. *Then click on the Data tab and select ControlSource and
enter:
* =125.50+200+100+45+75

If you have field names
* =YourFieldName1+YourFieldName2+YourFieldName3...

You can now refer to it in code.
* msgbox "Sum is " & Me.Sumit

Thank, yes I'm doing it same. but I thought it may can do like MS
excel.- Hide quoted text -

- Show quoted text -

To different products; *You could try this. *Create a 2 text boxes;
Text0 and Text1. *In the controlsource of Text0 enter
* =Eval([Text1])
Now in Text1 you can enter 1 + 2 + 3 and the result will show up in
the other text box.- Hide quoted text -

- Show quoted text -
Thanks Patrick
Yes this is work. But I cant bond Text0.

Reply With Quote
  #12  
Old   
Lanka Danweem
 
Posts: n/a

Default Re: How to calculate form field - 08-13-2011 , 07:22 AM






On Aug 12, 10:23*pm, "Phil" <p... (AT) stantonfamily (DOT) co.uk> wrote:
Quote:
On 12/08/2011 07:36:11, Lanka Danweem wrote:





On Aug 11, 11:15*pm, Patrick Finucane <patrickfinucan... (AT) gmail (DOT) com
wrote:
On Aug 11, 2:05*am, Lanka Danweem <m... (AT) lankadanweempituwa (DOT) com> wrote:

How to calculate form field

Please any body know how to design a form with calculation on a field.
How can I format the table field to get result of form field.

Acturaly what I want is , when I ender numeric data to form field e.g
I want to sum 5 data (125.50+200+100+45+75) for one field without
calculate separately
Are there any format to enter these as excel cell to get result *of
545.50?.

Like this

= 125.50+200+100+45+75)

You can create a text box on a form. *If you open the property sheet
up for the text box and give it a name of Sumit by pressing on the
Other tab. *Then click on the Data tab and select ControlSource and
enter:
* =125.50+200+100+45+75

If you have field names
* =YourFieldName1+YourFieldName2+YourFieldName3...

You can now refer to it in code.
* msgbox "Sum is " & Me.Sumit

Thank, yes I'm doing it same. but I thought it may can do like MS
excel.

You could try this bit of code in an AfterUpdate of a unbound field called
Text0

Private Sub Text0_AfterUpdate()

* * Dim Stg As String, Letter As String
* * Dim Tot As Single
* * Dim i As Integer, j As Integer

* * If Left(Text0, 1) <> "=" Then Exit Sub

* * Stg = Right(Text0, Len(Text0) - 1) * * * * *' Lose the "="

* * For i = 1 To Len(Stg)
* * * * Letter = Mid(Stg, i, 1)
* * * * If Letter <> "0" _
* * * * And Letter <> "1" _
* * * * And Letter <> "2" _
* * * * And Letter <> "3" _
* * * * And Letter <> "4" _
* * * * And Letter <> "5" _
* * * * And Letter <> "6" _
* * * * And Letter <> "7" _
* * * * And Letter <> "8" _
* * * * And Letter <> "9" _
* * * * And Letter <> "." _
* * * * And Letter <> "+" Then
* * * * * * MsgBox "This is not a simple sum", vbInformation
* * * * * * Exit Sub
* * * * End If
* * Next i

* * i = 0
NextFigure:
* * i = InStr(i + 1, Stg, "+") * * * * * *' First "+"
* * If i = 0 Then * * * * * * * * * * * ' no "+" single figure
* * * * Tot = Tot + CSng(Mid(Stg, j + 1, Len(Stg) - j))
* * * * GoTo PrintIt
* * Else
* * * * Tot = Tot + CSng(Mid(Stg, j + 1, i - j - 1))
* * End If
* * j = i
* * GoTo NextFigure
PrintIt:
* * Text0 = Tot

End Sub

Phil- Hide quoted text -

- Show quoted text -
Thanks Pill ,,, This code not work for me.

Reply With Quote
  #13  
Old   
Phil
 
Posts: n/a

Default Re: How to calculate form field - 08-13-2011 , 11:52 AM



On 13/08/2011 13:22:04, Lanka Danweem wrote:
Quote:
Thank, yes I'm doing it same. but I thought it may can do like MS
excel.

You could try this bit of code in an AfterUpdate of a unbound field calle
d
Text0

Private Sub Text0_AfterUpdate()

* * Dim Stg As String, Letter As String
* * Dim Tot As Single
* * Dim i As Integer, j As Integer

* * If Left(Text0, 1) <> "=" Then Exit Sub

* * Stg = Right(Text0, Len(Text0) - 1) * * * * *' Lose th
e "="

* * For i = 1 To Len(Stg)
* * * * Letter = Mid(Stg, i, 1)
* * * * If Letter <> "0" _
* * * * And Letter <> "1" _
* * * * And Letter <> "2" _
* * * * And Letter <> "3" _
* * * * And Letter <> "4" _
* * * * And Letter <> "5" _
* * * * And Letter <> "6" _
* * * * And Letter <> "7" _
* * * * And Letter <> "8" _
* * * * And Letter <> "9" _
* * * * And Letter <> "." _
* * * * And Letter <> "+" Then
* * * * * * MsgBox "This is not a simple sum", vbInformation
* * * * * * Exit Sub
* * * * End If
* * Next i

* * i = 0
NextFigure:
* * i = InStr(i + 1, Stg, "+") * * * * * *' First "+"
* * If i = 0 Then * * * * * * * * * * * ' no
"+" single figure
* * * * Tot = Tot + CSng(Mid(Stg, j + 1, Len(Stg) - j))
* * * * GoTo PrintIt
* * Else
* * * * Tot = Tot + CSng(Mid(Stg, j + 1, i - j - 1))
* * End If
* * j = i
* * GoTo NextFigure
PrintIt:
* * Text0 = Tot

End Sub

Phil- Hide quoted text -

- Show quoted text -

Thanks Pill ,,, This code not work for me.

In what way dosen't it work.? Are you getting wrong results or does it crash

Send an examp-le of the figures you are using

Phil
Ph

Reply With Quote
  #14  
Old   
Access Developer
 
Posts: n/a

Default Re: How to calculate form field - 08-14-2011 , 12:29 AM



"Lanka Danweem" <mail (AT) lankadanweempituwa (DOT) com> wrote

Quote:
Yes this is work. But I cant bond Text0.
I told you how to accomplish what you want, that is, to save the calculated
value into the database.

You simply cannot, repeat canNOT, bind a calculated Control, because the
Control Source contains the calculations and is, thus, not available to use
for binding the Control to a Field. Read this, re-read it, and re-read it
again until you understand it.

Then re-read my response in which I tell you how to do so, with a little VBA
code, and a bound Control with it's Visible property set to False if you
don't want it to show, along with the value in the calculated Control.

--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.