Setting Clear Button

dsomers

Registered User.
Local time
Today, 20:28
Joined
Nov 13, 2003
Messages
131
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:

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
 
I would guess that you have those fields set to "Required" in the design of the table.

Why don't you just move to a new record if you need all of the fields emtpy which I am guessing is to input data into a new record.
 
I actually got it fixed. What I was trying to do was fill in half the information and try to clear it to start a new entry (ie. made a mistake on data entry). I just set the Required back to no and used the VB code and used an Undo button to clear. I guess I was trying to do it the hard way.. hehe...

Thanks!
David Somers
 

Users who are viewing this thread

Back
Top Bottom