Text Box Validation

Lamb2087

Registered User.
Local time
Today, 22:19
Joined
Feb 7, 2003
Messages
103
When you advance the record selector to a new record and only enter text in one text box rather than five is there a way to have a message bax come up and say you need to enter text in all text boxes?
 
Hello,

the easiest "non-coding" way would be to make them all required fields (if none of them can ever be empty).

This is done at the table design screen - look for "Required".

Other then that, your gonna have to code it I would think.
In the after_update part of the form, put something like:
if text1.text ="" AND text2.text ="" AND text3.text="" AND text4.text="" AND text5.text="" THEN
msgbox "Please enter text in all five required fields."
End if

Hope that helps!

-Sean
 
Validation

Sean
Thanks i'll give it a try
 
I used the code in my form to check for null value (Placed in the click function of a button or in form close works well):

If IsNull(Me.YourFieldHere) Then
MsgBox "Your message here"
DoCmd.GotoControl "YourField1 Here"

ElseIF IsNull(Me.YourField2Here) Then
MsgBox "Your message here"
DoCmd.GotoControl "YourField2 Here"

ElseIF IsNull(Me.YourField3Here) Then
MsgBox "Your message here"
DoCmd.GotoControl "YourField3 Here"

ElseIF IsNull(Me.YourField4Here) Then
MsgBox "Your message here"
DoCmd.GotoControl "YourField4 Here"

ElseIF IsNull(Me.YourField5Here) Then
MsgBox "Your message here"
DoCmd.GotoControl "YourField5 Here"

End If



The Message box is optional if you don't want it. You can add Beep there instead to make it beep at the user.


Hope this helps.

Faceman
 
Query question

Faceman
I have a query question, are you good with append queries?
 
You should also test for empty strings just incase the user starts to key data in a text box and then deletes the data. The field is no longer null if they do that.

If IsNull(YourFieldHere1) Or YourFieldHere1 = "" Then
MsgBox "Your message here"
DoCmd.GotoControl "YourField1 Here"

HTH
 
RE: Query Question

Hudson,
Good thinking. I have the code tied to a combo box on my form, so checking for zero length was not an issue with me. Glad you added that bit. =)


Lamb,
Well, one thing is for sure... If I can't answer it, I am definately sure someone here can. These guys are a fount of information. Just reading these forums has helped me out more than I can say.

So go ahead and post, or give me a link to your post in the query forum.



Faceman
 
Validation Code

Do you start out with Private sub ??()
Validation Code

End Sub

How do you start the private sub?

As for queries It is listed un Lamb2087 in the query section.
 
RE: Validation code

How is it you are wanting to invoke the code? There are several ways you can do it...

From the field Lost Focus - In the form design mode, go to the field's properties and click the event tab. You will see the title "On Lost focus". Click the event builder using code. Place the code in the window that opens up.

Command button - Same as above, but it will be the title "On Click".

Form Close - Again, same as above, but on the form's properties under the title "On Close".


I personally used mine under the form's On Close event, but it depends on your personal preference.


Faceman
 
Text box Validation

I have two forms that are subforms within a main form. In the subforms there are text boxes that can be filled out to add data. I wanted to make the fields that need info to let the user know if they were not filled completely out. This would be when the user moves from one text box to another or when the user advances to a new record by the controls at the bottom of the form.

Can you suggest the code to accomplish this?
 
I suggest that you use the design view of the table to set the "Validation Rule" for each field to "Is Not Null" (without the quotes). Set the "Validation Text" for each field to "The X field must not be null!". That will prevent a new record from being saved if any of the fields you "set" in the table from being Null.

HTH
 
Validation

How would you validate a text box that is supposed to be filled in with text so when some one enteres a number they can not advance to the next text box until corrected. I am using a sql table linked to a access db so I do not have the options of the validation rule and text like I would in access tables.
 
Validation for text not numbers

I have this code listed below to validate for text to be entered in a text box so when you enter numeric values you are presented with a message box.

Private Sub ITEM_DESC_BeforeUpdate(Cancel As Integer)
Dim Pos, strChar

Pos = 1
If IsNull(txtITEM_NUM) Then Exit Sub

For Pos = 1 To Len(txtITEM_NUM)
strChar = Mid(txtITEM_DESC, Pos, 1)
If (strChar >= "0" And strChar <= "9") Then
MsgBox "Must be Text only"
Cancel = True
Exit Sub
End If
Next Pos


End Sub

Only problem is this is not showing a message box when you tyoe in numerica values.
 
I would use the OnKey event of the text box to test if they press a non numeric key.
This might be overkill but it prevents a user from typing most non numeric keys.

Code:
Private Sub tbItemDesc_KeyPress(KeyAscii As Integer)
On Error GoTo Err_tbItemDesc_KeyPress
    
    'Convert keyed characters to uppercase and reject keyed numbers
    If KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Then
        KeyAscii = 0
        Beep
        MsgBox "''Item Description'' can not contain a number.", vbInformation, "Invalid Item Description"
    ElseIf KeyAscii = Asc("/") Or KeyAscii = Asc("\") Or KeyAscii = Asc("'") Or KeyAscii = Asc(".") _
        Or KeyAscii = Asc("@") Or KeyAscii = Asc("#") Or KeyAscii = Asc("$") Or KeyAscii = Asc("\") _
        Or KeyAscii = Asc("(") Or KeyAscii = Asc(")") Or KeyAscii = Asc("*") Or KeyAscii = Asc("-") Or KeyAscii = Asc("_") Then
        KeyAscii = 0
        Beep
        MsgBox "''Item Description'' can not contain any non alpha characters.", vbInformation, "Invalid Item Description"
    Else
        KeyAscii = Asc(UCase(Chr(KeyAscii)))
    End If
    
Exit_tbItemDesc_KeyPress:
    Exit Sub
    
Err_tbItemDesc_KeyPress:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_tbItemDesc_KeyPress
    
End Sub
HTH
 
Iwant to validate for text

I want to be able to validate for letters and it some one enters a number, show a dialog box stating no numerica values allowed.
 
Which OnKey Event???

OnKey Up, Down, Press do you want me to put the code??

I want to valdate that the user has entered letters instead of numbers.
 
Use the On Key Press event. The sub name that I post yesterday would have been your clue as to which event I was using...

Private Sub tbItemDesc_KeyPress(KeyAscii As Integer)

HTH
 
It now works thanks to ghudson

Yes It now works.

Some one was trying to tell me to use the Input Mask with a L as the criteria, but this did not work. Do you know what they were trying to do?
 
How about letters and number combination

I have a text box where the user enters an a before the number
is there a way to tell them to enter an a if they have not in the text box?

My other text boxes are either letters or numbers, this is the only with a combination.
 
You could try to an Input Mast to auto fill the "a" for them. Is there a standard length for the number like four numbers looking like this "a1234"? If so, try this for an Input Mask...
"a"0000;;#

Check the help files for Input Mask for more options.

HTH
 

Users who are viewing this thread

Back
Top Bottom