473,387 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VB Calculate and update field in a Form

Hi all!

I want to take the value from one form-field, deduct the VAT and return the
value in another form-field. I have made a Public Function for this and
attached it to the text-box. Can anybody help me with the correct syntax?

Here's what I got so far:

Public Function specify_VAT()
Dim vat
vat = "[price]/1.24"
End Function

I suppose what I want to know is how to put the result of this into the
form-field in question. Any thought appreciated.

Sven

Nov 12 '05 #1
3 8230
You need this twice, once after update of the price and once OnCurrent of
the form so that you get the correct value for each record.
I am assuming you have one field called Price, bound to a field in a table,
and one field called Vat which is unbound on your form.

Private Sub Price_AfterUpdate()

Dim VatRate As Single
VatRate = 17.5 ' UK Vat Rate

Vat = Price / (1 + VatRate / 100) * VatRate / 100

End Sub

I think it is bad policy to hard code in the VAT Rate, greedy governments
keep wanting more. Much better to hold this in a table

Phil
"Sven Seljom" <sv**@seljom.no> wrote in message
news:5v******************@news4.e.nsc.no...
Hi all!

I want to take the value from one form-field, deduct the VAT and return the value in another form-field. I have made a Public Function for this and
attached it to the text-box. Can anybody help me with the correct syntax?

Here's what I got so far:

Public Function specify_VAT()
Dim vat
vat = "[price]/1.24"
End Function

I suppose what I want to know is how to put the result of this into the
form-field in question. Any thought appreciated.

Sven

Nov 12 '05 #2
Thanks Phil

Your assumptions are correct, but how to I bind this Sub to the Vat-field,
and how is it fired?

"Phil Stanton" <ph**@stantonfamily.co.uk> skrev i melding
news:3f*********************@mercury.nildram.net.. .
You need this twice, once after update of the price and once OnCurrent of
the form so that you get the correct value for each record.
I am assuming you have one field called Price, bound to a field in a table, and one field called Vat which is unbound on your form.

Private Sub Price_AfterUpdate()

Dim VatRate As Single
VatRate = 17.5 ' UK Vat Rate

Vat = Price / (1 + VatRate / 100) * VatRate / 100

End Sub

I think it is bad policy to hard code in the VAT Rate, greedy governments
keep wanting more. Much better to hold this in a table

Phil
"Sven Seljom" <sv**@seljom.no> wrote in message
news:5v******************@news4.e.nsc.no...
Hi all!

I want to take the value from one form-field, deduct the VAT and return

the
value in another form-field. I have made a Public Function for this and
attached it to the text-box. Can anybody help me with the correct syntax?
Here's what I got so far:

Public Function specify_VAT()
Dim vat
vat = "[price]/1.24"
End Function

I suppose what I want to know is how to put the result of this into the
form-field in question. Any thought appreciated.

Sven


Nov 12 '05 #3
You didn't set the value into the Function but you need to. Do that, and put
it in the Control Source of the Control. (I assume you don't want to store a
value that you can calculate when you need it.). I think if I was deducting
VAT, I'd call the function something other than "specify_VAT", too? And I'd
pass the price as an argument so I could reuse the Function if I needed it
elsewhere, too. Phil may have a good point, too, about the VAT changing --
unless there are different VAT rates used for different locales, a Public
(global) Constant would be an option to keeping it in a table.

Thus, I might have a Control Source of

= PriceWithoutVAT([Price])

Larry Linson
Microsoft Access MVP

"Sven Seljom" <sv**@seljom.no> wrote in message
news:5v******************@news4.e.nsc.no...
Hi all!

I want to take the value from one form-field, deduct the VAT and return the value in another form-field. I have made a Public Function for this and
attached it to the text-box. Can anybody help me with the correct syntax?

Here's what I got so far:

Public Function specify_VAT()
Dim vat
vat = "[price]/1.24"
End Function

I suppose what I want to know is how to put the result of this into the
form-field in question. Any thought appreciated.

Sven

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Building Blocks | last post by:
Hi, All I need is a simle calculate form script which contains this: A script that can handle text input, radio buttons, checkboxes, and dropdowns. Each one of these variables will contain a...
6
by: jochen scheire | last post by:
Is there a way I can calculate a field in a form based on another field in the same form. When clicking submit, both values should be posted to the next page. I want to be able to type in a value...
3
by: BlackFireNova | last post by:
This concerns an Access 2002 (XP) database. There are two fields, "Notes" (Memo Field) and "Notes Update" on a form (among others) which I am concerned with here. Problem: I need to be able...
4
by: Sven Seljom | last post by:
I want to take the value from one form-field, deduct the VAT and return the value in another form-field. I have made a Public Function for this and attached it to the text-box. Can anybody help me...
4
by: Rich_C | last post by:
I'm sure this is very simple, but I have very little experience with javascript -- and what I do know isn't helping me here. I have a simple form where users can enter a quantity (qty) and cost...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
6
by: luanhoxung | last post by:
dear all!! i met the headache problem in setting value for some controls in my form. i have 2 combo box in form F1. i want to set value for some textbox in F1 when i choose value from 2 combo...
2
by: reidarT | last post by:
I have 3 fields in an aspx page. The 3. field should be the sum of field A and field B I use OnTextChanged to calculate the sum in field3. At the same time I want to insert the content of theese 3...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.