Hello all! I'm using required fields and found some code to use in another thread, but I'm trying to set a clear button on my form and it gives me an error about having to enter certain fields afterwards. Here is the code:
When I try to hit clear it will clear everything but when I hit close, it will say "You must enter the following fields: Date of Birth, Drivers License #, Building #, Lease Start Date, Lease End Date, Monthly Rent.
Any ideas on whats going wrong?
Thanks!
David Somers
Code:
Private Sub cmdClear_Click()
Me.ContactFirstName = vbNullString
Me.ContactLastName = vbNullString
Me.Previous_Address = vbNullString
Me.Text26 = vbNullString
Me.Text28 = vbNullString
Me.Text30 = vbNullString
Me.DOB = vbNullString
Me.SSN = vbNullString
Me.DL__ = vbNullString
Me.Text42 = vbNullString
Me.Text44 = vbNullString
Me.Lease_Start_Date = vbNullString
Me.Lease_End_Date = vbNullString
Me.Deposit = 0
Me.MonthlyRent = vbNullString
Me.chkActive = vbNullString
End Sub
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
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
When I try to hit clear it will clear everything but when I hit close, it will say "You must enter the following fields: Date of Birth, Drivers License #, Building #, Lease Start Date, Lease End Date, Monthly Rent.
Any ideas on whats going wrong?
Thanks!
David Somers