Again with validation

donkey9972

Registered User.
Local time
Today, 11:57
Joined
May 18, 2008
Messages
54
Hi, I am sorry to keep beating a dead horse but I need a bit more help on validation. I have my form with an unbound field. I need the information to simply be a 0 or a 1 that the user enters. If anything else I need a message box to pop up and say, it needs to be 0 or 1.

So I have tried using the validation rule and text, which worked fine until I ran into an issue. The issue was this, when the user input anything into the field other than a 1 or 0 but decided to cancel inputting anything, it still popped up requiring them to change what they put to a 1 or 0 before cancelling without a popup message. Is there anyway to suppress this popup message if the user inputs anything other than a 1 or 0 and decides to simply cancel instead of continuing to input data?
 
Your logic does not really make sense - but sounds like what you mean is it needs to be 0, 1 or Null (assuming it is not a required field)
 
here is a demo open form1.
 

Attachments

Well, I do realize what I am asking is a bit strange and confusing. Your demo works perfectly Arnel, however I have 5 fields on the form and I only need 1 specific field to need this requirement, the other 4 fields have other data that need input. But I just need to figure out how to modify things. Thank you both.
 
Ok I figured out how to modify the code on the sample DB you uploaded Arnel. I think I have it working, but i will play around with it and make sure. Again thank you.
 
Ok I figured out how to modify the code on the sample DB you uploaded Arnel. I think I have it working, but i will play around with it and make sure
on design view, add a Tag (any text) to the textbox you need to validate.
then change the Load event to:
Code:
Private Sub Form_Load()
    Dim ctrl As Control
   
    For Each ctrl In Me.Controls
        If TypeOf ctrl Is TextBox Then
            If ctrl.Tag = "the Tag you have on the control here" Then
            ' Assign the Change event to call the function
            ctrl.OnChange = "=TextBox_Change('" & ctrl.Name & "')"
            End If
        End If
    Next ctrl
End Sub
 
When you say the field must be zero or one, have you considered a check-box? There you would get 0 or -1, but there cannot be anything else in such a control. Take away the choice of entering something else. And it is unbound, so you will only test it for FALSE (or 0) and anything else. Then it becomes trivial to have a default value of 0 (FALSE) and they don't need to enter anything.

I'm thinking along operational procedure lines but you know the actual intent of what you are doing. I'm just offering the idea of an alternative method to get a 0/non-0 value in an unbound control.
 
I need the information to simply be a 0 or a 1 that the user enters. If anything else I need a message box to pop up and say, it needs to be 0 or 1.
What is the purpose of this unbound field? Why are you not simply using code in the Form's BeforeUpdate event? You are keeping your process a secret so we have to guess. My guess is that you are asking the user to confirm something but what? why? I'm sure there is a more logical and simpler method of confirming an entry. Surely validating data in the form's BeforeUpdate event is even better.
 

Users who are viewing this thread

Back
Top Bottom