check numeric value by vba code

J

Johnny

Hi,

any ideas on how to check a numeric value in a field - that is so the new value are between ex 1000 and 10000 before any further action happens. Im trying to do this by a function that returns a value to my event (Not in list) så that if the function are true the not in list event are carried out. If false i want the user to get a msgbox "This value isnt suported, plesase go back and correct the value"

Im new at this and would be very grateful for any help at all!!
 
A

Alex Dybenko

i think you can use control's beforeupdate event:

if me.MyTextbox < 1000 or me.MyTextbox > 10000 then
msgbox "This value isnt suported, plesase go back and correct the value"
cancel=true
end if

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com


Johnny said:
Hi,

any ideas on how to check a numeric value in a field - that is so the new
value are between ex 1000 and 10000 before any further action happens. Im
trying to do this by a function that returns a value to my event (Not in
list) sa that if the function are true the not in list event are carried
out. If false i want the user to get a msgbox "This value isnt suported,
plesase go back and correct the value".
 
J

Johnny

Hmm, that dosent quite do the trick for me because the not in list event gets fired anyway.. is there any way to abort that event if ex your code is true?



----- Alex Dybenko wrote: ----

i think you can use control's beforeupdate event

if me.MyTextbox < 1000 or me.MyTextbox > 10000 the
msgbox "This value isnt suported, plesase go back and correct the value
cancel=tru
end i

--
Alex Dybenko (MVP
http://Alex.Dybenko.co


Johnny said:
value are between ex 1000 and 10000 before any further action happens. I
trying to do this by a function that returns a value to my event (Not i
list) sa that if the function are true the not in list event are carrie
out. If false i want the user to get a msgbox "This value isnt suported
plesase go back and correct the value"
 
J

Johnny

hi, this i more exactly what happens

if i aply a validation rule at tabel level the not in list event that is on a combo box causes the newly entered value to be aplied to the table via a separate form. Because the validation rule is broken the value is not acepted and the form cant be closed. I have to go into vba code and manually stop this before the form can be closes.

What i want to do is to have a not in list event that triggers a new form to open and add the numeric value to the underlying table. BUT not if this new value dosent meet a criteria (greater than and less than). The following code is what i have so far

Dim strMsg As Strin

strMsg = "'" & NewData & "' Dosent exist" & vbCrLf & vbCrL

strMsg = strMsg & "Want to add the new post?
strMsg = strMsg & vbCrLf & vbCrLf & "Click yes for new value and No to go back and retype.

If MsgBox(strMsg, vbQuestion + vbYesNo, "Legg til nytt") = vbNo The
Response = acDataErrContinu
Me.Und
Els
DoCmd.OpenForm "Form", , , , acAdd, acDialog, NewDat
Response = acDataErrAdde
End I
End Su

and in the load form even

If Me.NewRecord And Not IsNull(Me.OpenArgs) The
Me![Nummer] = Me.OpenArg
End I

I tried some variants of <> in these events but nothing seems to work.
 
J

John Spencer (MVP)

Test the value of newData immediately

If Val(NewData) < 1000 or Val(NewData) > 10000 Then
MsgBox "Invalid Data"
Response = acDataErrContinue
ELSE 'Run your existing code
Strmsg = ...
End if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top