From: Luciano on 3 Jun 2010 07:18 Is there a way to prevent input a Text-when the field requires a numeric input? Perhaps there is a function that test the input-type? Something like: Sub txtField_BeforeUpdate if "txtField is not Numeric" then MsgBox "Please give a number" SendKeys "{esc}" Cancel = True end if End Sub
From: Tom van Stiphout on 3 Jun 2010 10:23 On Thu, 3 Jun 2010 04:18:11 -0700, Luciano <balloonplanning(a)skynet.be> wrote: There is of course the IsNumeric function. But I typically let Access deal with data type issues: just define the fields in the tables correctly, and use bound forms. Access will complain if the wrong data type is used. -Tom. Microsoft Access MVP >Is there a way to prevent input a Text-when the field requires a numeric input? >Perhaps there is a function that test the input-type? >Something like: > >Sub txtField_BeforeUpdate >if "txtField is not Numeric" then > MsgBox "Please give a number" > SendKeys "{esc}" > Cancel = True >end if >End Sub
From: Daniel Pineault on 3 Jun 2010 10:38 You had the concept. You can use the IsNumeric() function to test the input value is a numeric value. Also, if you setup your table format property... when the user input the wrong data format they will automatically be notified. -- Hope this helps, Daniel Pineault http://www.cardaconsultants.com/ For Access Tips and Examples: http://www.devhut.net Please rate this post using the vote buttons if it was helpful. "Luciano" wrote: > Is there a way to prevent input a Text-when the field requires a numeric input? > Perhaps there is a function that test the input-type? > Something like: > > Sub txtField_BeforeUpdate > if "txtField is not Numeric" then > MsgBox "Please give a number" > SendKeys "{esc}" > Cancel = True > end if > End Sub
From: Marshall Barton on 3 Jun 2010 11:33 Luciano wrote: >Is there a way to prevent input a Text-when the field requires a numeric input? >Perhaps there is a function that test the input-type? >Something like: > >Sub txtField_BeforeUpdate >if "txtField is not Numeric" then > MsgBox "Please give a number" > SendKeys "{esc}" > Cancel = True >end if >End Sub No code needed. Assuming your numbers are positive integers, try setting the text box's ValidationRule property to something like: Not Like "*[!0-9]*" and set the ValidationText property to your message. IMPORTANT NOTE You should NOT use SendKeys, it has several problems that can cause weird things such as messing with the NumLock key. In this case, you would use: Me.txtfield.Undo -- Marsh MVP [MS Access]
From: Luciano on 4 Jun 2010 01:56 Thank you so much. I did have many times problems with the NumLock (Random On/Off). So I can modifie some code and hope that it will prevend this malfunction. "Marshall Barton" wrote: > Luciano wrote: > > >Is there a way to prevent input a Text-when the field requires a numeric input? > >Perhaps there is a function that test the input-type? > >Something like: > > > >Sub txtField_BeforeUpdate > >if "txtField is not Numeric" then > > MsgBox "Please give a number" > > SendKeys "{esc}" > > Cancel = True > >end if > >End Sub > > > No code needed. Assuming your numbers are positive > integers, try setting the text box's ValidationRule property > to something like: > Not Like "*[!0-9]*" > and set the ValidationText property to your message. > > IMPORTANT NOTE > You should NOT use SendKeys, it has several problems that > can cause weird things such as messing with the NumLock key. > In this case, you would use: > Me.txtfield.Undo > > -- > Marsh > MVP [MS Access] > . >
|
Next
|
Last
Pages: 1 2 Prev: shorter method than elseif Next: Show only queries w/table source combo box |