A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

addition with in a field



 
 
Thread Tools Display Modes
  #1  
Old August 17th, 2005, 09:59 PM
haggr
external usenet poster
 
Posts: n/a
Default addition with in a field

I want to be able to set focus in a field, then enter "3 + 4" and when
hitting "=", the value in that field will be "7"
  #2  
Old August 17th, 2005, 10:31 PM
Klatuu
external usenet poster
 
Posts: n/a
Default

Using the "=" would add a layer of complexity and reduce response time,
because you would have to use either the KeyPress or KeyDown events which
will have to evaluate every keystroke.

Here is a way that will give you the same results regardless of how the text
box (not a field, fields are in tables) is exited:
In the after update event of the text box:
Me.MyTextBoxName = Eval(Me.MyTextBoxName)
You will need to ensure you have an error handler in the event procedure,
because if a user enters a value that cannot be evaluated, it will cause an
error.

"haggr" wrote:

I want to be able to set focus in a field, then enter "3 + 4" and when
hitting "=", the value in that field will be "7"

  #3  
Old August 18th, 2005, 04:59 AM
Allen Browne
external usenet poster
 
Posts: n/a
Default

You will need to provide an unbound text box on your form where the user can
enter the calcuation. In its AfterUpdate event procedure, use Eval() to
evaluate the expression, and assign the result to your field.

Example:

Private Sub txtCalc_AfterUpdate
If IsNull(Me.txtCalc) Then
Me.[MyField] = Null
Else
Me.[MyField] = Eval(Me.txtCalc)
End If
End Sub

Note that you will need error handling in case the user enters something
that makes no sense--typically error 2431.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"haggr" wrote in message
...
I want to be able to set focus in a field, then enter "3 + 4" and when
hitting "=", the value in that field will be "7"



 




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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help to merge Image (Doug Robins?) JohnB Mailmerge 21 June 23rd, 2005 05:28 PM
Design help, please SillySally Using Forms 27 March 6th, 2005 04:11 AM
LOOKUP FOR A VALUE ON A TABLE Samora New Users 9 February 22nd, 2005 01:06 PM
Syntax needed to get needed reports Frank Lueder New Users 15 January 6th, 2005 08:39 AM
New Record Update Michelle Using Forms 5 October 28th, 2004 07:59 AM


All times are GMT +1. The time now is 03:15 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.