Required field error message (1 Viewer)

diversoln

Registered User.
Local time
Today, 23:41
Joined
Oct 8, 2001
Messages
119
What is a good way to let the user know that he/she hasn't filled in all the required fields on a form. The default message comes up and says something like, "you can't go to the next record" but this doesn't tell them why.

Out of about 20 fields on my form, 8 of them are required. If the user skips a required field, I'd like a message to pop-up that specifically tells them, "please fill in the date,(or employee name, facility, etc) it's required"

Any suggestions?

Thanks!
 

dgm

Registered User.
Local time
Tomorrow, 08:41
Joined
Sep 5, 2002
Messages
146
U can use something like this in the before update event of your form:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    Dim strFields As String
    strFields = checkFields
    If strFields <> "" Then
        MsgBox "Please fill in the following fields:" & vbNewLine & strFields
        Cancel = True
    End If
End Sub

Function checkFields() As String
    If IsNull(Me.myName) Then
        checkFields = addToString(checkFields, "Name")
    End If
    If IsNull(Me.MyTitle) Then
        checkFields = addToString(checkFields, "Title")
    End If
    If IsNull(Me.MyNum) Then
        checkFields = addToString(checkFields, "Number")
    End If
End Function

Function addToString(strOrig As String, strToAdd As String) As String
    If strOrig = "" Then
        addToString = strToAdd
    Else
        addToString = strOrig & ", " & strToAdd
    End If
End Function
 

diversoln

Registered User.
Local time
Today, 23:41
Joined
Oct 8, 2001
Messages
119
T-Riffic ! This works nicely. Thanks!
 

dsomers

Registered User.
Local time
Today, 23:41
Joined
Nov 13, 2003
Messages
131
I have tried implementing this code and it is still giving me errors. Here's the code I'm using:

Private Function checkFields() As String

If IsNull(Me.ContactFirstName) Then

checkFields = addToString(checkFields, "First Name")

End If

If IsNull(Me.ContactLastName) Then

checkFields = addToString(checkFields, "Last Name")

End If

If IsNull(Me.Previous_Address) Then

checkFields = addToString(checkFields, "Previous Address")

End If

If IsNull(Me.Text26) Then

checkFields = addToString(checkFields, "City")

End If

If IsNull(Me.Text28) Then

checkFields = addToString(checkFields, "State")

End If

If IsNull(Me.Text30) Then

checkFields = addToString(checkFields, "ZIP")

End If

If IsNull(Me.DOB) Then

checkFields = addToString(checkFields, "Date of Birth")

End If

If IsNull(Me.SSN) Then

checkFields = addToString(checkFields, "SSN")

End If

If IsNull(Me.DL__) Then

checkFields = addToString(checkFields, "Driver License Number")

End If

If IsNull(Me.Text42) Then

checkFields = addToString(checkFields, "Building Number")

End If

If IsNull(Me.Text44) Then

checkFields = addToString(checkFields, "Unit Number")

End If

If IsNull(Me.Lease_Start_Date) Then

checkFields = addToString(checkFields, "Lease Start Date")

End If

If IsNull(Me.Lease_End_Date) Then

checkFields = addToString(checkFields, "Lease End Date")

End If

If IsNull(Me.Deposit) Then

checkFields = addToString(checkFields, "Security Deposit")

End If

If IsNull(Me.MonthlyRent) Then

checkFields = addToString(checkFields, "Monthly Rent")

End If

End Function

Private Function addToString(strOrig As String, strToAdd As String) As String

If strOrig = "" Then

addToString = strToAdd

Else

addToString = strOrig & ", " & strToAdd

End If

End Function
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click


DoCmd.Close

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click

End Sub


When I try to close the window without entering any data, I get this error: The Expression On Click you entered as the event property setting produced the following error: Procedure declaration does not match description of event of procedure having the same name.

What am I doing wrong? And what does this error mean?

Thanks!
David Somers
 

dgm

Registered User.
Local time
Tomorrow, 08:41
Joined
Sep 5, 2002
Messages
146
Do u have any other code in that same form/module?

An AxtiveX control maybe?
 

dsomers

Registered User.
Local time
Today, 23:41
Joined
Nov 13, 2003
Messages
131
I got it figured out. I had the required settings in a few columns in my table set incorrectly.

Thanks!
David Somers
 

soundsfishy

Registered User.
Local time
Tomorrow, 08:41
Joined
Sep 25, 2002
Messages
174
Thanks Matey (DGM)

Ive been after something like that code for ages I just havent been able to get it right!. I works just nicely

I envy your state(QLD), wish I was there right now!.
 
Last edited:

dsomers

Registered User.
Local time
Today, 23:41
Joined
Nov 13, 2003
Messages
131
Thank God for AC/DC... I've got all their CD's... hehe.

Later,
David Somers
 

dgm

Registered User.
Local time
Tomorrow, 08:41
Joined
Sep 5, 2002
Messages
146
Yup, nice and warm up here :cool:

What's it like in Melbourne?


My bro has all their cd's too :D

What's your favourite song?
 

diversoln

Registered User.
Local time
Today, 23:41
Joined
Oct 8, 2001
Messages
119
Hello again,

This code has been working very nicely on my development version of the db. (I'm using Access 2002 to develop).

This week I took the db in to my client (they are using Access 2000) and now its not working quite right. When the user partially fills out the form and presses the CLOSE FORM button, the message box pops up and the user presses OK after reading it. Then instead of allowing the user to enter the missing data on the form, the form just closes losing all the data he has entered.

Any ideas?
 

dgm

Registered User.
Local time
Tomorrow, 08:41
Joined
Sep 5, 2002
Messages
146
Ahhh yeah i see what u mean.

Only thing i can think of is to disable/remove the close button (x) and create your own close button on the form. The add some checking into that as well:
Code:
Private Sub cmdClose_Click()
    Dim strFields As String
    strFields = checkFields
    If strFields <> "" Then
        MsgBox "Please fill in the follwing fields:" & vbNewLine & strFields
    Else
        DoCmd.Close
    End If
End Sub
 

Users who are viewing this thread

Top Bottom