I've got a routine to check for values in some fields (I'm not using Field-Required because this is a context distinct from the usual use of the table). If they aren't filled I want to cancel the Update and give user another chance to fill the boxes if "Retry" is chosen. When I step through this with "Retry" selected I get the "Can't save record at this time--Still want to close object" box. WHY???
[tt]
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Add
Dim ctrl As Control
Dim strPrompt As String
strPrompt = "You haven't filled in all the fields" & vbCrLf & "The Site won't be added without all fields "
strPrompt = strPrompt & vbCrLf & "Press Retry to fill in fields or Cancel to close without saving"
For Each ctrl In Me.Controls
If ctrl.Tag = "Required" Then
If TypeOf ctrl Is TextBox And IsNull(ctrl.Value) Then
If MsgBox(strPrompt, vbExclamation + vbRetryCancel, "INFO NEEDED" = vbRetry Then
Cancel = True
Exit For
Else
Cancel = True
GoTo CloseWithoutAdd
End If
End If
End If
Next
Exit_Err_Add:
Exit Sub
CloseWithoutAdd:
DoCmd.Close acForm, "frm_AddSites_pop", acSaveNo
Exit Sub
Err_Add:
MsgBox Err.Description
Resume Exit_Err_Add[/tt]
[tt]
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Add
Dim ctrl As Control
Dim strPrompt As String
strPrompt = "You haven't filled in all the fields" & vbCrLf & "The Site won't be added without all fields "
strPrompt = strPrompt & vbCrLf & "Press Retry to fill in fields or Cancel to close without saving"
For Each ctrl In Me.Controls
If ctrl.Tag = "Required" Then
If TypeOf ctrl Is TextBox And IsNull(ctrl.Value) Then
If MsgBox(strPrompt, vbExclamation + vbRetryCancel, "INFO NEEDED" = vbRetry Then
Cancel = True
Exit For
Else
Cancel = True
GoTo CloseWithoutAdd
End If
End If
End If
Next
Exit_Err_Add:
Exit Sub
CloseWithoutAdd:
DoCmd.Close acForm, "frm_AddSites_pop", acSaveNo
Exit Sub
Err_Add:
MsgBox Err.Description
Resume Exit_Err_Add[/tt]