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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|