Is there a code to validate form?

accessdummy

Registered User.
Local time
Today, 03:41
Joined
Sep 7, 2003
Messages
44
Hi,

Just wondering if someone is kind enough to generate VB codes to validate form.

Basically, this is what I need:

1) convert all data in text boxes to uppercase

2) to ensure that users key in all fields.

3) compare the new data with the database date to ensure no duplication, else it will prompt error and discard the new data.

4) display friendly error messages.

Preferably, the 4 criterias can be jumbled into one code.

Million thanks.
 
I'm using Access 97 in Win XP env..
Please give me Access 97 compliant VB codes.

Million thanks
 
1) The UCase() function or the StrConv function will both perform the opration you wish.

2) There are a few ways to do this:
  • At table level, set each field to required.
  • In the BeforeUpdate event of the form:
    Code:
    Dim ctl As Control
    For Each ctl In Me.Controls
        If ctl.ControlType = acTextbox Or ctl.ControlType = acCombobox Then
            If IsNull(ctl) Then
                MsgBox "You have not entered all the data.", vbExclamation"
                ctl.SetFocus
                Exit Sub
            End If
        End If
    Next

3) Clarify what you mean by the "database date"

4) use the MsgBox command as evidenced in the code snippet above.
 
Many thanks.

How do I use the Ucase()? WHere do I place the code?

Afterupdate of each textbox?
 
Yep, the AfterUpdate event would be fine.

Or, in the form's BeforeUpdate with the code above:

Code:
Dim ctl As Control
For Each ctl In Me.Controls
    If ctl.ControlType = acTextbox Or ctl.ControlType = acCombobox Then
        If IsNull(ctl) Then
            MsgBox "You have not entered all the data.", vbExclamation"
            ctl.SetFocus
            Exit Sub
        Else
            ctl = UCase(ctl)
        End If
    End If
Next
 

Users who are viewing this thread

Back
Top Bottom