473,387 Members | 1,700 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.

Very simple expression question

Hi,

I'm making a quick database and need to use an expression. I have no idea what I'm doing.

I would like the user to be able to input a number in one field, have Access perform a simple calculation on it (*.34) and spit the result back out into another text box and save it in the database.

I'm trying to use the "AfterUpdate" thing but I have no idea on syntax or anything.

Thanks in advance.
Aug 9 '10 #1
30 1767
NeoPa
32,556 Expert Mod 16PB
Stephen, I'm glad you asked.

It's not simple and it's not recommended. Let me start from the beginning...

Calculating the value is very simple. Expressions can be added into a query or a form easily enough. What is strongly recommended against (See Normalisation and Table structures) is saving the value of a calculation that is repeatable. If B is always equal to A * 0.34, then B should never be stored. It should always be worked out on the fly.

The only time a calculation should be stored is when you want to make a note of the historical condition ==> B = A * 0.34; A changes; B should not change to reflect the new value of A.

The expression needed in the query is simply :
Expand|Select|Wrap|Line Numbers
  1. B: [A] * .34
This will make both [A] and [b] available to your form.

Welcome to Bytes!
Aug 9 '10 #2
NeoPa, thanks for the help and the quick reply! I am completely new to Access and as per usual I'm having to teach myself rather than being sent on a course :(

So I apologise for this but, where do I put the equation? The calculation could be done on the fly I suppose. It's for calculating how much a print costs. So I have this:

BW_cost: [BW_Clicks] * 0.34

Typed into the "After Update" property of the BW_cost input box but it doesn't work.
Aug 9 '10 #3
NeoPa
32,556 Expert Mod 16PB
Is [BW_Cost] an existing field in your table?

This is an important question. You could say the crux of the matter.
Aug 9 '10 #4
In a word, yes.
Aug 9 '10 #5
NeoPa
32,556 Expert Mod 16PB
Clear answers are always good :)

Did you understand the comments I made in my post #2? About not storing data that can reliably be worked out?

The technique I recommend relies on the control being unbound you see. A calculated value cannot be applied to a bound control (which you would have if you were saving the value in a field).
Aug 9 '10 #6
I think I understood, yes. I didn't realise you couldn't apply a calculated value to a bound control. So the thing to do is to "un-bind" the control and try again. I will have a go at that tomorrow as I am now going home for the day. Thanks very much for your help.
Aug 9 '10 #7
NeoPa
32,556 Expert Mod 16PB
No worries.

Be aware. This means the value will no longer be stored in your table (which is as it should be). It can always be available when needed though (Hence it's the ideal and recommended solution).
Aug 9 '10 #8
Hi again,

Right, I've been struggling with this on and off all day and think I'm very nearly there!

I now have two calculations working (hurrah!) and then another one that adds the two together (double hurrah!). The user types in a number and Access performs the necessary calculations. I have done this by typing:

=[B+W Clicks]*0.034

Into the control source property of an unbound text box and then:

=[b]+[C]

Into another unbound text box. So far so good.

The problem is that in order to see the calculations I have to exit the form and then go back in. How can I make it update straight away?

Thanks in advance (again). :)
Aug 10 '10 #9
NeoPa
32,556 Expert Mod 16PB
In my test version it updates immediately. I can't imagine what you may be doing differently to cause this not to occur.

Perhaps a detailed description of what you have on your form might help. Otherwise we could look at getting a copy of your database posted. See below for instructions I prepared earlier :

When attaching your work please follow the following steps first :
  1. Remove anything not relevant to the problem. This is not necessary in all circumstances but some databases can be very bulky and some things do not effect the actual problem at all.
  2. Likewise, not entirely necessary in all cases, but consider saving your database in a version not later than 2003 as many of our experts don't use Access 2007. Largely they don't want to, but some also don't have access to it. Personally I will wait until I'm forced to before using it.
  3. If the process depends on any linked tables then make local copies in your database to replace the linked tables.
  4. If you've done anything in steps 1 to 3 then make sure that the problem you're experiencing is still evident in the updated version.
  5. Compile the database (From the Visual Basic Editor select Debug / Compile {Project Name}).
  6. Compact the database (Tools / Database Utilities / Compact and Repair Database...).
  7. Compress the database into a ZIP file.
  8. When posting, scroll down the page and select Manage Attachments (Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.) and add this new ZIP file.
It's also a good idea to include some instructions that enable us to find the issue you'd like help with. Maybe some instructions of what to select, click on, enter etc that ensures we'll see what you see and have the same problems.
Aug 10 '10 #10
I am running Access 2007 if that makes a difference. If I try to save it into an earlier format and the form doesn't go with it, just the table.
Aug 10 '10 #11
NeoPa
32,556 Expert Mod 16PB
I'm not sure what you're saying Stephen. Let me see if I can clarify.

2007 databases are not something I can even open, so I won't be able to help unless it's regressed at least to 2003.

I don't understand why a form would not be available after regressing. I've not heard that stated before.

Have you followed all the instructions? I must admit asking about posting as 2007 leads me to believe perhaps you haven't. Please read through them all. The issue may be a compilation one, in which case we should deal with that directly rather than trying to work out what other issues may result from a database that is already known to fail to compile.
Aug 10 '10 #12
I found the form. It was hiding, sorry about that. I will have another go at this tomorrow. Again, I appreciate all your help and patience.
Aug 10 '10 #13
NeoPa
32,556 Expert Mod 16PB
No worries. Tomorrow is fine :)
Aug 10 '10 #14
Morning. I have been through your instructions and attached the file. I've looked all over Google for a solution too but have been unable to find one. Very grateful for any help you can give. Thanks.
Aug 11 '10 #15
NeoPa
32,556 Expert Mod 16PB
There is no file attached Stephen :(
Aug 11 '10 #16
That's weird, I definitely uploaded it. Clicked on "Manage Attachments" etc. I'll try again. It's uploading now.
Attached Files
File Type: zip TEST - MRC Database 2010-2011.zip (242.9 KB, 63 views)
Aug 11 '10 #17
NeoPa
32,556 Expert Mod 16PB
It's certainly there now Stephen. I cannot download when in the office but I'll look from home later :)
Aug 11 '10 #18
You're a diamond. Thank you.
Aug 11 '10 #19
>>>> Just thought I'd *bump* this up in the hope someone might have an answer. :)

Hi again,

Right, I've been struggling with this on and off all day and think I'm very nearly there!

I now have two calculations working (hurrah!) and then another one that adds the two together (double hurrah!). The user types in a number and Access performs the necessary calculations. I have done this by typing:

=[B+W Clicks]*0.034

Into the control source property of an unbound text box and then:

=[b]+[C]

Into another unbound text box. So far so good.

The problem is that in order to see the calculations I have to exit the form and then go back in. How can I make it update straight away?

Thanks in advance (again). :)
Aug 13 '10 #20
NeoPa
32,556 Expert Mod 16PB
Sorry Stephen. I'm glad you bumped.

I thought I had 3 threads last night that I needed to look up as they had outstanding work to do but were no longer flagged as I'd read the latest post already. I had a hunt when I was home but only found the other two I'm afraid.

I'll look at this over the weekend for you. Again, sorry.
Aug 13 '10 #21
NeoPa
32,556 Expert Mod 16PB
I'm sorry Stephen. I've downloaded the database now, but your instructions are missing.

Something to do with [b] & [C] but I couldn't find any references to them in the database.

If you notice the text at the bottom of post #10 you'll see I suggest posting something so I can find your problem. I think you still need to do that if I'm to be of any more help.
Aug 15 '10 #22
Hi, thanks for your continued patience. Thanks to your help I've very nearly managed to get this working.

Basically, in the form "2010-2011 Data" there are three tabs. In the third tab, "Admin" there are two boxes, labelled "B+W Clicks" and "Colour Clicks".

Entering a number in either of those two boxes calculates a cost which appears in "B+W Click Cost" and "Colour Click cost" respectively.

These two are then added together and the result appears in "Total Click Charge".

My problem is that in order for these calculations to actually take place, you have to come out of the form and go back in. I would like it to update straight away but I have no idea how to achieve this.

Thanks.
Aug 16 '10 #23
NeoPa
32,556 Expert Mod 16PB
I don't have the db with me here atm so can I ask you now, what are the actual names of the TextBox controls (or if they are the names you've given, then what labels are near that I will recognise them by)?
Aug 16 '10 #24
In the form "2010-2011 Data" there are three tabs. In the third tab, "Admin" there are two boxes, labelled "B+W Clicks" and "Colour Clicks". These are the two text boxes that the user inputs a number into.

Entering a number in either of those two boxes calculates a cost which appears in "B+W Click Cost" and "Colour Click cost" respectively.
Aug 16 '10 #25
NeoPa
32,556 Expert Mod 16PB
I'm sorry Stephen. I got tied up till nearly 02:00 this morning on another, quite complicated, issue for a friend here.

I won't be around much tonight either, but tomorrow I have booked as holiday so I'll give it some serious attention then.
Aug 17 '10 #26
That would be great. But there's no hurry, please don't put yourself out too much.
Aug 17 '10 #27
NeoPa
32,556 Expert Mod 16PB
This isn't going to be good news for you Stephen, but it works perfectly for me!

As soon as I leave either of the two controls (after changing the value of course) the related calculated control updates perfectly. I made no changes first, it just ran and worked.

I suspect there may be something about your Access setup that is causing the difference, but I can't think of anything.

BTW your label shows .34p for the clicks but the calculation uses 0.034 (IE. 3.4p).
Aug 18 '10 #28
Bugger. I wonder what the problem could be then. I am using Access 2007 but I can't see why that would be the problem. I only just installed it using the "standard install" option so can't have changed anything since then. guess I'll contact Microsoft tech support. Thanks for all your help.

Thanks for the tip re: the calculation too :).
Aug 19 '10 #29
Just one last idea. When you say you "ran" it. Do you mean you opened the database, opened the form in form view and it worked or did you export it in some way?
Aug 19 '10 #30
NeoPa
32,556 Expert Mod 16PB
I'm sorry to say it was definitely the former. I just opened the form and tested. I was expecting to see what you described, but it updated immediately. It was only afterwards I even looked to see whether you had implemented it as a formula within the unbound controls (as indeed you had) or had effected it with code in the AfterUpdate() event procedure of the bound controls.
Aug 19 '10 #31

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gene Ellis | last post by:
Very simple question. If I have the XML file below: <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="newspage.xsl"?> <newspage> <content>Click here for blah...
4
by: Daniel | last post by:
I'm having a tough time getting text and image to align in a table. When I add the image for some reason the text in that cell shifts to the bottom of the cell. Below is the code and the result. ...
7
by: cppaddict | last post by:
The following code compiles but errors at runtime: int main() { std::string* str; str->insert(0,"test"); std::cout << *str; } Why does this not work? How can I fix it?
3
by: Winston Smith | last post by:
Hi, I have question about compiling multiple source files with templates using gcc. It's probably obvious but I'm new to C++. I've tried to isolate my problem and it came down to this. Lets...
3
by: Sahil Malik | last post by:
In VS2003 - add a page. Add a button Add a textbox. Set EnableViewState = False for all 3 above. Put some code behind on Button (anything). Run the sample - type something in the textbox -...
2
by: James | last post by:
I have a very simple datagrid, with an edit button that I added in PropertyBuilder. This fires the EditCommand event just fine and I show a panel where the user can edit certain fields. I have a...
6
by: Michael | last post by:
Hi, I have the following in some code: char temp; .....stuff.... for(i = 0; i < MAX_INPUT_LENGTH; i++){ if(temp == ":"){
1
by: Raycaster | last post by:
I'm 3/4 finished 2 simple VB apps for a upcoming silent auction being held at my children's school. Very Simple - This is what it does: 1st app allows input and builds a text database Unit...
0
by: pritch20001 | last post by:
Hi, I have been asked to build a simple web service by Friday and wondered if someone could help me out with a couple of questions. All I need to do is pass the contents of an XML file to...
2
by: sweeneye | last post by:
its the most basic thing in the world but im just getting started with access and VB, i am more used to C++ but still a bit hazy on that too, anyway its a simple names database which to start with we...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.