My subform recordsource property is a table.And the code,
I think below code prevent the form from saving the records,
especially when it opened as a subform.
This is my *MAIN FORM* code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate
Dim strMessage As String
Dim intResponse As Integer
intResponse = MsgBox("Is the spec correct?", vbYesNoCancel, "Confirm")
Select Case intResponse
Case vbYes
If IsNull(Me.Model) Then
strMessage = strMessage & _
" Enter Model Name" & vbCrLf
End If
If InputVoltage.Value < 11 Then
strMessage = strMessage & _
" Input Voltage rate " & vbCrLf
End If
If SpeedMode_opt.Value = 1 And _
Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If
If SpeedMode_opt.Value = 1 And _
Freeaircurrentlolimit1.Value = 0 And _
Freeaircurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If
If SpeedMode_opt.Value = 1 And _
Lockcurrentlolimit1.Value = 0 And _
Lockcurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Lock Current spec 1 " & vbCrLf
End If
If SpeedMode_opt.Value > 1 And _
Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If
If SpeedMode_opt.Value > 1 And _
Freeaircurrentlolimit1.Value = 0 And _
Freeaircurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If
If SpeedMode_opt.Value > 1 And _
Lockcurrentlolimit1.Value = 0 And _
Lockcurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Lock Current spec 1 " & vbCrLf
End If
If SpeedMode_opt.Value > 1 And _
Rotationspeedlolimit2.Value = 0 And _
Rotationspeedhilimit2.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 2 " & vbCrLf
End If
If SpeedMode_opt.Value > 1 And _
Freeaircurrentlolimit2.Value = 0 And _
Freeaircurrenthilimit2.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 2 " & vbCrLf
End If
If SpeedMode_opt.Value > 1 And _
Lockcurrentlolimit2.Value = 0 And _
Lockcurrenthilimit2.Value = 0 Then
strMessage = strMessage & _
" Input Lock Current spec 2 " & vbCrLf
End If
If SpeedMode_opt.Value = 4 And _
DutyFreq_txt.Value = 0 Then
strMessage = strMessage & _
" Input Duty Frequency rate " & vbCrLf
End If
If Len(strMessage) = 0 Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
Forms![Revision spec_frm]![Spec revision
history].Form![Remark_txt].SetFocus
Else
Cancel = True
MsgBox strMessage, vbOKOnly, "Errors"
End If
Case vbNo
If MsgBox("Cancel spec revision ? ", vbOKCancel, "Confirm") = vbOK
Then
Me.Undo
End If
Cancel = True
Case vbCancel
Cancel = True
End Select
Exit_Form_BeforeUpdate:
Exit Sub
Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate
End Sub
============================
The mainform code produce below error message before updated the record :
" The macro or function set to the BeforeUpdate or ValidationRule property
for
this field is preventing Microsoft Access from saving the data in the field"
I don't know what field.
=======================================================
And below are my *SUB FORM* code
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMessage As String
If IsNull(Me.Remark_txt) Then
strMessage = strMessage & _
" Leave some note in 'Remark' field " & vbCrLf
End If
If Len(strMessage) = 0 Then
MsgBox " Revision Complete ", vbOKOnly, "Information"
DoCmd.Close acForm, "Revision spec_frm"
Else
Cancel = True
MsgBox strMessage, vbOKOnly, "Error"
End If
End Sub
John W. Vinson said:
What's the Subform's Recordsource property? Do you have any code on the form
or the subform?
John W. Vinson [MVP]