check decimal and if numeric

I have an unbound textbox, txtAmount.  I want to make sure that user
enters only two decimal places, and that the input is numeric.

I tried using InputMask 99999999.99 which works for positive numbers,
but that mask won't allow the minus sign (or plus sign) to be used.
So, how can I allow input of a negative number?  Currently, if
TransactType is "Payment", it takes the value in Amount * -1 (if
existing Amount > 0), so that effectively makes it a negative.  But, a
TransactType of "Adjustment" could be either negative or positive. I
could make a TransactType of "Adjustment-negative" and
"Adjustment-positive", but there will probably be additional
TransactTypes added later, so think that might get me into trouble.

I can use If Not IsNumeric to check for numeric, but then I can't
check (or just don't know how) for number of decimal places.

Any suggestions? Thanks
John
0
johnboy7676
1/11/2008 11:03:44 PM
access.formscoding 7493 articles. 0 followers. Follow

3 Replies
950 Views

Similar Articles

[PageSpeed] 20

Personally, I hate input masks. There's probably a better way.

From your description, it seems that you want to make sure that:
a) the value is a valid number, and
b) the value has no more than 2 significant digits after the decimal.

For (a), set the text box's Format property to a numeric value, such as 
Fixed. Set Decimal Places to 2 if you want to always show the 2 places. 
Alternatives might be to use General Number (if the 2 places are really 
optional) or Currency (if that makes cents.)

For (b), use the AfterUpdate event procedure of the text box to round the 
value. This kind of thing:
    Private Sub Text0_AfterUpdate()
        Me.Text0 = Round(Me.Text0, 2)
    End Sub

-- 
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.

<johnboy7676@yahoo.com> wrote in message
news:nvsfo39ds1bt11153jh1iqc8gduoo2vshs@4ax.com...
>I have an unbound textbox, txtAmount.  I want to make sure that user
> enters only two decimal places, and that the input is numeric.
>
> I tried using InputMask 99999999.99 which works for positive numbers,
> but that mask won't allow the minus sign (or plus sign) to be used.
> So, how can I allow input of a negative number?  Currently, if
> TransactType is "Payment", it takes the value in Amount * -1 (if
> existing Amount > 0), so that effectively makes it a negative.  But, a
> TransactType of "Adjustment" could be either negative or positive. I
> could make a TransactType of "Adjustment-negative" and
> "Adjustment-positive", but there will probably be additional
> TransactTypes added later, so think that might get me into trouble.
>
> I can use If Not IsNumeric to check for numeric, but then I can't
> check (or just don't know how) for number of decimal places.
>
> Any suggestions? Thanks
> John 

0
Allen
1/12/2008 2:05:50 AM
I set the Format property as you suggested. That did prevent text from being
entered. And yes, that makes "cents"..-)

As for second suggestion, if for example, they input 25.228 instead of 25.22
then it would round to 25.23 when should be 25.22.  And, if truncate at two
decimals, who's to say the third or fourth digit was the one that was in error?
Maybe the first digit after the decimal was the mistake.

I found something while searching google, it was suggested to use a Validation
Rule of :
=int(myfield*100)/100  
which seems to work.  I'm not sure why, but it does seem to work. (originally
posted by "Turtle")

Thanks,  lots of good info on your web site, btw.  


>Personally, I hate input masks. There's probably a better way.
>
>From your description, it seems that you want to make sure that:
>a) the value is a valid number, and
>b) the value has no more than 2 significant digits after the decimal.
>
>For (a), set the text box's Format property to a numeric value, such as 
>Fixed. Set Decimal Places to 2 if you want to always show the 2 places. 
>Alternatives might be to use General Number (if the 2 places are really 
>optional) or Currency (if that makes cents.)
>
>For (b), use the AfterUpdate event procedure of the text box to round the 
>value. This kind of thing:
>    Private Sub Text0_AfterUpdate()
>        Me.Text0 = Round(Me.Text0, 2)
>    End Sub
>
>-- 
>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.
>
><johnboy7676@yahoo.com> wrote in message
>news:nvsfo39ds1bt11153jh1iqc8gduoo2vshs@4ax.com...
>>I have an unbound textbox, txtAmount.  I want to make sure that user
>> enters only two decimal places, and that the input is numeric.
>>
>> I tried using InputMask 99999999.99 which works for positive numbers,
>> but that mask won't allow the minus sign (or plus sign) to be used.
>> So, how can I allow input of a negative number?  Currently, if
>> TransactType is "Payment", it takes the value in Amount * -1 (if
>> existing Amount > 0), so that effectively makes it a negative.  But, a
>> TransactType of "Adjustment" could be either negative or positive. I
>> could make a TransactType of "Adjustment-negative" and
>> "Adjustment-positive", but there will probably be additional
>> TransactTypes added later, so think that might get me into trouble.
>>
>> I can use If Not IsNumeric to check for numeric, but then I can't
>> check (or just don't know how) for number of decimal places.
>>
>> Any suggestions? Thanks
>> John 


0
John
1/12/2008 3:44:42 AM
Okay, you have it solved.

Int() rounds down, so effectively truncates an subsequent digits for 
positive numbers. It's different when you round negative numbers down, e.g.:
    - $2.281
would round down to:
    - $2.29

If you don't want that behavior, use Fix() instead of Int().

-- 
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.

"John" <johnboy7676@yahoo.com> wrote in message
news:m9dgo358innuf6rq343i3ron25bpf08kbl@4ax.com...
>I set the Format property as you suggested. That did prevent text from 
>being
> entered. And yes, that makes "cents"..-)
>
> As for second suggestion, if for example, they input 25.228 instead of 
> 25.22
> then it would round to 25.23 when should be 25.22.  And, if truncate at 
> two
> decimals, who's to say the third or fourth digit was the one that was in 
> error?
> Maybe the first digit after the decimal was the mistake.
>
> I found something while searching google, it was suggested to use a 
> Validation
> Rule of :
> =int(myfield*100)/100
> which seems to work.  I'm not sure why, but it does seem to work. 
> (originally
> posted by "Turtle")
>
> Thanks,  lots of good info on your web site, btw.
>
>
>>Personally, I hate input masks. There's probably a better way.
>>
>>From your description, it seems that you want to make sure that:
>>a) the value is a valid number, and
>>b) the value has no more than 2 significant digits after the decimal.
>>
>>For (a), set the text box's Format property to a numeric value, such as
>>Fixed. Set Decimal Places to 2 if you want to always show the 2 places.
>>Alternatives might be to use General Number (if the 2 places are really
>>optional) or Currency (if that makes cents.)
>>
>>For (b), use the AfterUpdate event procedure of the text box to round the
>>value. This kind of thing:
>>    Private Sub Text0_AfterUpdate()
>>        Me.Text0 = Round(Me.Text0, 2)
>>    End Sub
>>
>>-- 
>>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.
>>
>><johnboy7676@yahoo.com> wrote in message
>>news:nvsfo39ds1bt11153jh1iqc8gduoo2vshs@4ax.com...
>>>I have an unbound textbox, txtAmount.  I want to make sure that user
>>> enters only two decimal places, and that the input is numeric.
>>>
>>> I tried using InputMask 99999999.99 which works for positive numbers,
>>> but that mask won't allow the minus sign (or plus sign) to be used.
>>> So, how can I allow input of a negative number?  Currently, if
>>> TransactType is "Payment", it takes the value in Amount * -1 (if
>>> existing Amount > 0), so that effectively makes it a negative.  But, a
>>> TransactType of "Adjustment" could be either negative or positive. I
>>> could make a TransactType of "Adjustment-negative" and
>>> "Adjustment-positive", but there will probably be additional
>>> TransactTypes added later, so think that might get me into trouble.
>>>
>>> I can use If Not IsNumeric to check for numeric, but then I can't
>>> check (or just don't know how) for number of decimal places.
>>>
>>> Any suggestions? Thanks
>>> John
>
> 

0
Allen
1/12/2008 4:58:43 AM
Reply:

Similar Artilces:

no notification from list control when check box selected?
hi there i have a list control in an MFC app for which i set CheckBoxes ON (LVS_EX_CHECKBOXES) i need to know when the user checks/unchecks any item is there a specific notification sent to the owner when the user checks/unchecks an item? or do i watch for the more general LVN_ITEM_CHANGED notification (which doesn't seem to give info specific to checking/unchecking - the closest thing seems to be a State Image Mask change)? tia bhu >i have a list control in an MFC app for which i set CheckBoxes ON >(LVS_EX_CHECKBOXES) > >i need to know when the user checks/unchecks any ...

No Spell Check
Some documents I receive in exel format have sections that I need to respond to then return to sender. Often the spell check option is not available in the tools menu. (its Not Darkened). Is there a way to turn the spell check option on? Thanks For Your Replies Patrick For a follow-up, see: http://www.msofficegurus.com/forum/forum_posts.asp?TID=9 -- Regards Robert Find me at http://www.msofficegurus.com - be part of it! ...

How do I create a check for an award presentation?
I am trying to create a blank check template to use for an award ceremony. If you want an actual check you will need to put in the routing and account numbers. Why not use one of your own checks for a guide? -- Don Vancouver, USA "gdshred" <gdshred@discussions.microsoft.com> wrote in message news:35BC2BFD-54E0-4E62-AE43-4BB637A5B4C3@microsoft.com... >I am trying to create a blank check template to use for an award ceremony. Believe or not I have a .wmf blank check on my web site, you can use it as a guide. http://msauer.mvps.org/graphics.htm It is zip file, 9kb. ...

Check printing from Msmoney
I cannot get my msmoney 2003 to print a single check by itself without having at least 2 checks or more to be printed. Any suggestions as to what I can do to correct the situation where I can get a single check to print. With only one check to print and you try to print it says you do not have any accounts with checks to be printed. You can put in another check to print and it works ok. Help?????? ...

How to Check if an opportunity has been Idle for a set time
Hi, I need to create a workflow that sends an email to the record owner if the Opportunity has not been modified for 42 days (6 weeks). I have two questions 1) how do I check the date from when the modified date has been changed and perform the date comparision, I assume using the "wait" feature?, 2) if a workflow has started counting days, and the record is modified, does the workflow reset itself if someone does modify the record, or is a new workflow created, if so, what happens to the ogininal workflow? Thanks Ilja G ...

Check if a value is legal
I have some fields I need to check against another table. The scenario: My users have been inputting data in my tables through queries up until now. i've realized I'm going to need a few lookuptables to verify their input, but there's some 10.000+ records that needs to be checked. So I've made the lookup tables but I thought I'd make it a little easier for my users to verify their data with a query that returns records with faults. I've made a query that returns al the NULL values and a continuous form that mark the empty but required fields with yellow b...

Running Check box code after Command button Click
Private Sub CommandButton1_Click() Call CheckBox2_Click End Sub I have code like the following and it works almost like I want it to, but when I check the checkbox it will activate the Form worksheet I have. I do not want anything to happen until after the command button is pressed. What can I add or remove to this code to allow this to happen? Thanks! Option Explicit Private Sub CommandButton1_Click() Call CheckBox2_Click End Sub Private Sub CheckBox2_Click() Sheets("Form").Activate ActiveSheet.Range("Address").Select If Selection.Interior.Pattern = xlNone ...

Option & Check Boxes
How do I use these boxes in a questionnaire? Hi SJ (SJ@discussions.microsoft.com), in the newsgroups you posted: || How do I use these boxes in a questionnaire? SJ, are you speaking of a print publication or is this for web design? -- Brian Kvalheim Microsoft Publisher MVP http://www.publishermvps.com This posting is provided "AS IS" with no warranties, and confers no rights. ...

Spell check 02-22-10
How do I activate spell check in Vista please It is activated. Do you want it to *make* you check the spelling? Tools | Options | Spelling. Check the first box. -- Bruce Hagen MS-MVP [Mail] Imperial Beach, CA "Linda Jean" <Linda Jean@discussions.microsoft.com> wrote in message news:E0E28056-A0CC-4EF7-BFE1-01FEA61B51B3@microsoft.com... > How do I activate spell check in Vista please "Linda Jean" <Linda Jean@discussions.microsoft.com> schrieb im Newsbeitrag news:E0E28056-A0CC-4EF7-BFE1-01FEA61B51B3@microsoft....

How do I check for duplicate numbers in Excel?
I need to check a list for repeating or duplicate numbers. Hi check out http://www.cpearson.com/excel/duplicat.htm for anything to do with duplicates i'm sure you'll find what you need there. Cheers julieD "newbee101" <newbee101@discussions.microsoft.com> wrote in message news:B93A1374-02FE-40D7-BFD4-2901FDB4CB98@microsoft.com... >I need to check a list for repeating or duplicate numbers. Julie, I just wanted to comment on your link to CPearson. That site is FANTASTIC. I have learned so much from that site. I have added it to my favorites and will be u...

How do I create a spread sheet w/a numerator/denomenator?
I am creating a spread sheet that has different numerators and denomenators for each data point. I was going to use "fractions" (i.e. 2/3 = 2 out of 3 is positive) however it is then converted into simpler terms loosing the denomenator feature. Such as 2/4 is then changed to 1/2 so I lose the accuracy of the denomenator. Any ideas of how I can keep the integrity of both the numerator totals and the denomenator totals? Hi! Why not just enter them as text? '2/3 '2/4 Biff "Denise" <Denise@discussions.microsoft.com> wrote in message news:16B4F0D1-0A5A-...

How to check whether subtotals are on a worksheet
Hi, does anybody know a way of checking whether subtotals have been added to a worksheet using a macro?? Cheers, Alan How about just looking for "=subtotal("? Record a macro when you do it manually (edit|find) AlanAylett wrote: > > Hi, > > does anybody know a way of checking whether subtotals have been added > to a worksheet using a macro?? > > Cheers, Alan -- Dave Peterson ec35720@msn.com ...

How to check the dirty state of a CPropertyPage set by SetModified?
Hi, Anyone know how to check the dirty state of a Property Page? I have a pointer to a CPropertyPage and would like to know how to read the dirty sate set by SetModified for individual pages. Thanks Todd Todd Williams wrote: >Hi, > > Anyone know how to check the dirty state of a Property Page? > >I have a pointer to a CPropertyPage and would like to know how to read the >dirty sate set by >SetModified for individual pages. This is strangely absent functionality. I researched this myself a few weeks ago, and CPropertyPage used to maintain an undocumented boolean ...

Selecting Check Boxes
Problem: I have two columns which each has a check box. I want only one check post to be selected as the two are related i.e. which contractor will you use contractor 1 contractor 2 who has best rates contractor 1 contractor 2 etc etc when I use radio buttons for some strange reason it only ever allows me to check on radio button on the spreadsheet (could be stupid user syndrome!). Can anyone help with the best way to work this. thanks Not clear what you're saying, however, checkboxes ar...

not able to use Spell Check in Outlook Express...
I just bought a new computer. I am trying to use Outlook Express. The spell check feature is not present. I go to the help section on the tool bar and it tells me that Outlook Express doesn't have a spell check feature unless you have a Word programs (or Works, PowerPoint, etc.) I have Works 7.0, and it works fine. Why can't I use Spell Check in Outlook Express then? Please help, Thank you, Chris Billings This newsgroup is for support of Outlook 97, 98, 2000 & 2002 from the Office family for Windows PCs. For Outlook Express (OE) support try posting in one of these ne...

How to make checked tasks disappear in Outlook 2002/Covey PlanPlus...
Hi, I am using Franklin/Covey's Plan Plus for Outlook and I wanted to set it up so checked items (goals, tasks, etc.) are removed from the active list. I know Outlook can do this, but I don't remember where in the program the setting is. Tech support from Franklin/Covey said the only way is to manually delete it, but I am sure there is an automated way... Please post any help..thanks! Thanks! Frank ...

Converting numerical date to text
Does anyone know how to convert to text and keep the integrity of the numerical date? (example: 4/06/97 to 04061997) I can make it look okay, however; the cell is still reflecting the previous value. Not sure what you mean by "the cell is still reflecting the previous value". 1) Formatting doesn't affect the underlying value stored in the cell. Since XL stores dates as integer offsets from a base date, 4/06/97 is the displayed value for the number 35526 (windows default 1900 date system). You can change the formatting to Format/Cells/Number/Custom mmddyyyy but t...

Check out important update from Microsoft Corp.
--kqbgdpdzjeyljg Content-Type: multipart/related; boundary="isihwpeonuf"; type="multipart/alternative" --isihwpeonuf Content-Type: multipart/alternative; boundary="hdkqitgogragt" --hdkqitgogragt Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Microsoft User this is the latest version of security update, the "October 2003, Cumulative Patch" update which fixes all known security vulnerabilities affecting MS Internet Explorer, MS Outlook and MS Outlook Express. Install now to protect your computer from these vulnerabilities, the mo...

Formatting dollar or numeric values
I have a numeric field on the screen I wish to format with commas and, ideally, a dollar sign. Is there a "best" way to do this? Or must I just parse the value and insert the commas and dollar sign myself - and then strip them off when I retrieve the number. Isn't there some kind of formatting function available for edit fields that only handles the formatting on the screen but returns an unformatted value? -- Edward Fultz Sr. Software Engineer Pamet Systems Acton, Ma www.pametsystems.com As it seems with most of C++ (You would think they would at LEAST make a decent num...

Check Information
Good evening. I am new to Money for the most part. I used Money 2004 Standard and downloaded my bank transactions daily. I have upgraded to MS Money 2006 Deluxd and am trying to use the Online services and automatic updates. Money connects to Key Bank fine, but none of the check information is brought over (check number, memo, etc). So, I end up having to go to KeyBank anyway, so it doesn't seem to make a lot of sense to use the online services. That's where I've always gotten to. "langley111" <langley111@discussions.microsoft.com> wrote in message n...

Check printing #3
We have a user that began the check printing process in GP - the checks for the company printed okay, but when the check batch began posting, it errored out. Two of the batches eight transactions are available under series posting and say it is in historical, but the rest of the batch will not post. We have identified the transactions causing the problem but cannot see anything wrong with them. Can we do something other than voiding the entire batch and reprinting? The batch will be assigned the Status of Posting or Marked if there is a stop in processing or power fluctuation. 1....

Checking the results of a number of IF formula
Hi I am trying to verify that all the tests have passed in the Table below and show an over all pass. 1 B B C D 2 Lower Upper Measured Pass/Fail 3 309.6 379.5 344 =IF(AND(G21>E21,G21<F21),"Pass","Fail") 4 121.77 152.68 136.2 =IF(AND(G22>E22,G22<F22),"Pass","Fail") 5 268.2 332.75 301.9 =IF(AND(G23>E23,G23<F23),"Pass","Fail") 6 242.43 300.19 271.69 =IF(AND(G24>E24,G24<F24),"Pass","Fail") I have tried the following IF formula =IF...

Subtracting decimals
Why is this? ... In Excel if I subtract, for example, 1282.39 from 1282.40, and the answer cell is displayed with 14 or more decimal places, the result displays as 0.00999999999999, when in fact the correct result, obviously, is exactly 0.01. What's happening here, and how do I prevent it? Thanks. one of the 2 values that you are subtracting is not exactly a 2 decimal place numeral first make them such by using the round function and then when you subtract you should see 0.01 Conversely you could round the result: =round(b1-a1,2) where b1 = 1282.4 and a1 = 1282.39 "Mike A&quo...

PDC (Post Dated Checks)
Hi I would like to know what is the best way of handling PDC ( Post Dated Checks) both in Receivables and Payables? Thanks in Advance -Daniel Daniel Unless you have a customization or the date on the check is in a fiscal period that does not yet exist or is closed, GP is never going to be checking whether the date you're entering on a transaction is in the future. So you can enter any date you want on any transaction. That said, my 2 cents: - For payables, you don't really have a choice, you have to print the check from GP, but even if you didn't, entering any payment with...

How do I do an outstanding check import for first bank reconciliation
What are the steps that need to be taken within GP to import outstanding checks? I have already written the integration, but cannot recall the process. Amywhetzel, Are you running Integration Manager to import Bank Transactions? If so, the destination should be Bank Transaction Entry. You will want to be sure you don't post through GL or it will decrease your GL cash balance. Remember to enter your last bank balance per your statement into the Checkbook Maintenance window before you run your first reconciliation. Also, if any subledger transactions have been done after Bank R...