Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2004
    Posts
    47

    Unanswered: IsNull - Where am I making a mistake?

    I have a form which has a checkbox. When the checkbox is checked some fields become visible to the user to fill out. I would like to validate that when the checkbox is true and the fields are empty the user has to fill them out. I put the code in the button "save" and this is what I did:

    Code:
    Private Sub Save_Click()
    On Error GoTo Err_Save_Click
    
        If Loaned = True And IsNull(txtLoanedTo) Or IsNull(txtLoanedBy) Or IsNull(txtLoanDate) Or IsNull(txtExpectedReturnDate) Then
        If MsgBox("Please fill out the required information", vbOKOnly + vbExclamation, "Missing Data") = vbOK Then
        Me.txtLoanedTo.SetFocus
        Else
        DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
        DoCmd.Close acForm, Me.Name
        End If
        End If
    
    Exit_Save_Click:
    
        Exit Sub
    
    Err_Save_Click:
        MsgBox Err.Description
        Resume Exit_Save_Click
        
    End Sub
    Can anyone point out the mistake.

  2. #2
    Join Date
    Sep 2004
    Posts
    161
    I don't what's your problem but if i understand you must add "(" before the first isnull :
    If Loaned = True And (IsNull(txtLoanedTo) Or IsNull(txtLoanedBy) Or IsNull(txtLoanDate) Or IsNull(txtExpectedReturnDate) ) Then

  3. #3
    Join Date
    Sep 2004
    Posts
    47

    what is wrong

    I am sorry for. I did not specify what exactly was wrong.
    That code perfectly saves the information but when I fill out the information the "Else" statement is not going through. The function of that button is to:

    1) check if there are any required fields left unfilled and if so ask the user to fill them

    2) save the information if it is ok

    3) exit the form

    Well...the first 2 are ok but the form is not closing.

  4. #4
    Join Date
    Sep 2004
    Posts
    47

    Found it

    I found it. I should really learn following the syntax. Sorry.
    Should have been:

    Code:
    Private Sub Save_Click()
    On Error GoTo Err_Save_Click
    
        If Loaned = True And IsNull(txtLoanedTo) Or IsNull(txtLoanedBy) Or IsNull(txtLoanDate) Or IsNull(txtExpectedReturnDate) Then
        If MsgBox("Please fill out the required information", vbOKOnly + vbExclamation, "Missing Data") = vbOK Then
        Me.txtLoanedTo.SetFocus
        End If
        Else
        DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
        DoCmd.Close acForm, Me.Name
        End If
    
    Exit_Save_Click:
    
        Exit Sub
    
    Err_Save_Click:
        MsgBox Err.Description
        Resume Exit_Save_Click
        
    End Sub

  5. #5
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    yeah, you should indent your code blocks, so you can notice such errors easly .
    Code:
    Private Sub Save_Click()
    On Error GoTo Err_Save_Click If Loaned = True And IsNull(txtLoanedTo) Or IsNull(txtLoanedBy) Or IsNull(txtLoanDate) Or IsNull(txtExpectedReturnDate) Then If MsgBox("Please fill out the required information", vbOKOnly + vbExclamation, "Missing Data") = vbOK Then Me.txtLoanedTo.SetFocus End If Else DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 DoCmd.Close acForm, Me.Name End If Exit_Save_Click: Exit Sub Err_Save_Click: MsgBox Err.Description Resume Exit_Save_Click
    End Sub
    ghozy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •