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  

validation help



 
 
Thread Tools Display Modes
  #1  
Old November 27th, 2009, 10:20 AM posted to microsoft.public.access.forms
EddWood
external usenet poster
 
Posts: 6
Default validation help

I have a form with a discount option and need to set it so they maximum
value that can be entered is 100, what is the syntax to enter to ensure
users cannot enter any value greater than 100?

Thanks

  #2  
Old November 27th, 2009, 10:49 AM posted to microsoft.public.access.forms
Tore
external usenet poster
 
Posts: 12
Default validation help

If the discount is entered into a text field named txtDiscount you could do
it on the after update event of this field.

Private sub txtDiscount_AfterUpdate()
if not isnumeric (me.txtDiscount) then
Msgbox("You must enter a nunmeric value")
exit sub
end if

if me.txtDiscount 100 then
Msgbox("You cannot enter values over 100")
me.txtDiscount = ""
end if

End sub
  #3  
Old November 27th, 2009, 02:39 PM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default validation help

This type of validation code belongs in the textbox BeforeUpdate event; the
AfterUpdate event is too late, and focus will simply move to the next field
if the code is done there.

If the discount field is numeric, which it usually is, this will do the job:

Private Sub txtDiscount_BeforeUpdate(Cancel As Integer)
If Me.txtDiscount 100 Then
MsgBox ("You cannot enter values over 100")
Cancel = True
txtDiscount.SelStart = 0
txtDiscount.SelLength = Len(Me.txtDiscount)
End If
End Sub

Notice the

Cancel = True

line. This tells Access to not update the field's value, and returns focus to
the trextbox, so that the correction can be made. The lines

txtDiscount.SelStart = 0
txtDiscount.SelLength = Len(Me.txtDiscount)

hilites the incorrect data, making correction easier on the user.

--
Message posted via http://www.accessmonster.com

  #4  
Old November 30th, 2009, 01:29 PM posted to microsoft.public.access.forms
EddWood[_2_]
external usenet poster
 
Posts: 25
Default validation help

Hi Tore,

I have tried that code, but it still allows me to enter values greater than
100??

Any other suggestions?

Regards
Edd

"Tore" wrote in message
...
If the discount is entered into a text field named txtDiscount you could
do
it on the after update event of this field.

Private sub txtDiscount_AfterUpdate()
if not isnumeric (me.txtDiscount) then
Msgbox("You must enter a nunmeric value")
exit sub
end if

if me.txtDiscount 100 then
Msgbox("You cannot enter values over 100")
me.txtDiscount = ""
end if

End sub


  #5  
Old November 30th, 2009, 02:16 PM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default validation help

The code was tested and works as per your stated needs.

What datatype is txtDiscount?

I guess you need to copy your code and post it here.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200911/1

  #6  
Old November 30th, 2009, 02:31 PM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default validation help

Sorry, two more questions:

Did you remove the code from the AfterUpdate event?

What version of Access are you using?

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via http://www.accessmonster.com

  #7  
Old November 30th, 2009, 02:38 PM posted to microsoft.public.access.forms
EddWood[_2_]
external usenet poster
 
Posts: 25
Default validation help

cool guys, sorted it, my datatype is a SQL 'float' type and as such maximum
value is 1.0, sorry thanks for your help

Edd

"Linq Adams via AccessMonster.com" u28780@uwe wrote in message
news:9fe41ebd1774b@uwe...
The code was tested and works as per your stated needs.

What datatype is txtDiscount?

I guess you need to copy your code and post it here.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200911/1


  #8  
Old November 30th, 2009, 03:26 PM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default validation help

Glad you got it working!

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200911/1

 




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


All times are GMT +1. The time now is 08:49 PM.


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