Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Posts
    3

    Angry Unanswered: You Recieve no warning when closing a form with a required filed left null

    I have a large database I created. I created it with Access 2002 SP1. On this version if I leave a required field blank is automaticlly warns me. Now that we upgraded to Access 2002 SP2 it no longer does this.

    I saw a VB script online to fix this by creating a close command box. However the example only shows one required box. I have 14. Can someone please point me in the right direction to continue the if statements?

    Below is what I have:

    rivate Sub Command4_Click()

    If IsNull(Me![Test]) Then
    If MsgBox("'Test' must contain a value." & Chr(13) & Chr(10) & _
    "Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
    "Press 'Cancel'to abort the record.", _
    vbOKCancel, "A required filed is Null") = vbCancel Then
    DoCmd.Close
    Else
    Me![Field1].SetFocus
    End If
    Else
    DoCmd.Close
    End If

    If IsNull(Me![Field2]) Then
    If MsgBox("'Field2' must contain a value." & Chr(13) & Chr(10) & _
    "Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
    "Press 'Cancel'to abort the record.", _
    vbOKCancel, "A required filed is Null") = vbCancel Then
    DoCmd.Close
    Else
    Me![Field2].SetFocus
    End If
    Else
    DoCmd.Close
    End If

    Exit_Command4_Click:
    Exit Sub

    Err_Command4_Click:
    MsgBox Err.Description
    Resume Exit_Command4_Click

    On Error GoTo Err_Command4_Click
    End Sub

  2. #2
    Join Date
    Jan 2004
    Posts
    184

    Re: You Recieve no warning when closing a form with a required filed left null

    Private Sub Command4_Click()

    Dim ctrlObject As Control

    On Error GoTo ErrorHandler

    For Each ctrlObject In frmObject

    If (TypeOf ctrlObject Is TextBox) AND IsNull(Me![ctrlObject.Name]) then

    If MsgBox(ctrlObject.Name & " must contain a value." & Chr(13) & Chr(10) & _
    "Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
    "Press 'Cancel'to abort the record.", _
    vbOKCancel, "A required filed is Null") = vbCancel Then
    DoCmd.Close
    Else
    Me![CtrlObject.name].SetFocus
    End If
    Else
    DoCmd.Close
    End If

    end if

    Next ctrlObject

    end sub

    Also, I just wanted to share with you a control featured on download.com that I have been using that has made my life easier:

    http://download.com.com/3000-2404-10...ml?tag=lst-0-1

    After selecting the CursorType, CursorLocation, LockType and Disconnected status of your Recordset (there are defaults). I bind my controls and that is it All the complexities of ADO are hidden from the user which is you.

    Then I can Navigate, Add New, Delete, Refresh, Search and Save Changes to my recordsets without any other code. That is really it, no other code is needed.

    This works in any environment VB, Access, VC++ etc...

    Let me know what you think.

    Originally posted by mikesprint
    I have a large database I created. I created it with Access 2002 SP1. On this version if I leave a required field blank is automaticlly warns me. Now that we upgraded to Access 2002 SP2 it no longer does this.

    I saw a VB script online to fix this by creating a close command box. However the example only shows one required box. I have 14. Can someone please point me in the right direction to continue the if statements?

    Below is what I have:

    rivate Sub Command4_Click()

    If IsNull(Me![Test]) Then
    If MsgBox("'Test' must contain a value." & Chr(13) & Chr(10) & _
    "Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
    "Press 'Cancel'to abort the record.", _
    vbOKCancel, "A required filed is Null") = vbCancel Then
    DoCmd.Close
    Else
    Me![Field1].SetFocus
    End If
    Else
    DoCmd.Close
    End If

    If IsNull(Me![Field2]) Then
    If MsgBox("'Field2' must contain a value." & Chr(13) & Chr(10) & _
    "Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
    "Press 'Cancel'to abort the record.", _
    vbOKCancel, "A required filed is Null") = vbCancel Then
    DoCmd.Close
    Else
    Me![Field2].SetFocus
    End If
    Else
    DoCmd.Close
    End If

    Exit_Command4_Click:
    Exit Sub

    Err_Command4_Click:
    MsgBox Err.Description
    Resume Exit_Command4_Click

    On Error GoTo Err_Command4_Click
    End Sub

  3. #3
    Join Date
    Jan 2004
    Posts
    3
    Thanks for the help!! I'm sure that what I need but I'm just not a VB programmer. I cut and pasted that into the screen and it dont work. Below are the fields I have that are required. If you could just show me a few I'm know I could reproduce the work.

    Thanks so much!!!!

    Active Issue ----- Y/N
    Division ---------- Text
    System ---------- Text
    Level ------------- Text
    Shoteside ------- Text
    Failure ----------- Date/time
    Note ------------- Text
    Employee ------- Text
    Referrefnextlevel - Y/N
    Update ---------- Text
    Updatetime ----- Date/time

Posting Permissions

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