Where are my subform records..

S

shiro

Hi all,
I have a subform in my form.The records I entered to subform seems never
can be saved.When I check directly to subform's table,there is no any
record.
But if I entered the records directly to the forms while it's not as a
subforms,
the data can be saved and I found it in my table.
 
J

John W. Vinson

Hi all,
I have a subform in my form.The records I entered to subform seems never
can be saved.When I check directly to subform's table,there is no any
record.
But if I entered the records directly to the forms while it's not as a
subforms,
the data can be saved and I found it in my table.

What's the Subform's Recordsource property? Do you have any code on the form
or the subform?

John W. Vinson [MVP]
 
S

shiro

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
 
S

shiro

shiro said:
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]
 
J

Jeanette Cunningham

Hi Shiro,
some part of the code in the before update event is causing an error.
This line
Forms![Revision spec_frm]![Spec
revisionhistory].Form![Remark_txt].SetFocus
is something I would never do in a before update event.
I would put that code in the after update event for the form.

Comment out that line and run the form.
If that doesn't help, you will need to test each section of the code below.
For example comment out the 6 lines below and run the form.
You have to keep checking until you find the bit of the code that is causing
the error.

If SpeedMode_opt.Value = 1 And _
Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

I would also change all the If - End If's to select case statement where
suitable.
see code below
----------------------------------------------------------

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

Select Case SpeedMode
Case >=1
If Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

If Freeaircurrentlolimit1.Value = 0 And _
Freeaircurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If
. . . . . . .
'you put in the rest of the other conditions here

Case 4
If DutyFreq_txt.Value = 0 Then
strMessage = strMessage & _
" Input Duty Frequency rate " & vbCrLf
End If


Case Else
'handle any errors here

End Select

If Len(strMessage) = 0 Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
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
------------------------------------------------

Jeanette Cunningham




shiro said:
shiro said:
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:
Hi all,
I have a subform in my form.The records I entered to subform seems never
can be saved.When I check directly to subform's table,there is no any
record.
But if I entered the records directly to the forms while it's not as a
subforms,
the data can be saved and I found it in my table.


What's the Subform's Recordsource property? Do you have any code on the form
or the subform?

John W. Vinson [MVP]
 
S

shiro

I trap the last three lines:

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

And get the error is:
Run time error 2115

And the VBA highlight the:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

But still can not find any records in my subform.





Jeanette Cunningham said:
Hi Shiro,
some part of the code in the before update event is causing an error.
This line
Forms![Revision spec_frm]![Spec
revisionhistory].Form![Remark_txt].SetFocus
is something I would never do in a before update event.
I would put that code in the after update event for the form.

Comment out that line and run the form.
If that doesn't help, you will need to test each section of the code below.
For example comment out the 6 lines below and run the form.
You have to keep checking until you find the bit of the code that is causing
the error.

If SpeedMode_opt.Value = 1 And _
Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

I would also change all the If - End If's to select case statement where
suitable.
see code below
----------------------------------------------------------

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

Select Case SpeedMode
Case >=1
If Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

If Freeaircurrentlolimit1.Value = 0 And _
Freeaircurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If
. . . . . . .
'you put in the rest of the other conditions here

Case 4
If DutyFreq_txt.Value = 0 Then
strMessage = strMessage & _
" Input Duty Frequency rate " & vbCrLf
End If


Case Else
'handle any errors here

End Select

If Len(strMessage) = 0 Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
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
------------------------------------------------

Jeanette Cunningham




shiro said:
shiro said:
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






Hi all,
I have a subform in my form.The records I entered to subform seems never
can be saved.When I check directly to subform's table,there is no any
record.
But if I entered the records directly to the forms while it's not as a
subforms,
the data can be saved and I found it in my table.


What's the Subform's Recordsource property? Do you have any code on the
form
or the subform?

John W. Vinson [MVP]
 
J

Jeanette Cunningham

Shiro,
Access can't save the main form record. That error 2115 says something about
a function - are there any functions that get called on the main form?
We can't fix the subform problem until we fix the main form.
I suggest that you remove the source object from the subform control so that
we can just get the main form to work by itself..
Save the main without the subform, run the form and check the errors.
If still an error, comment out all the code on the before update event, run
the form and see if it will save records.


Jeanette Cunningham


shiro said:
I trap the last three lines:

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

And get the error is:
Run time error 2115

And the VBA highlight the:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

But still can not find any records in my subform.





Jeanette Cunningham said:
Hi Shiro,
some part of the code in the before update event is causing an error.
This line
Forms![Revision spec_frm]![Spec
revisionhistory].Form![Remark_txt].SetFocus
is something I would never do in a before update event.
I would put that code in the after update event for the form.

Comment out that line and run the form.
If that doesn't help, you will need to test each section of the code below.
For example comment out the 6 lines below and run the form.
You have to keep checking until you find the bit of the code that is causing
the error.

If SpeedMode_opt.Value = 1 And _
Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

I would also change all the If - End If's to select case statement where
suitable.
see code below
----------------------------------------------------------

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

Select Case SpeedMode
Case >=1
If Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

If Freeaircurrentlolimit1.Value = 0 And _
Freeaircurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If
. . . . . . .
'you put in the rest of the other conditions here

Case 4
If DutyFreq_txt.Value = 0 Then
strMessage = strMessage & _
" Input Duty Frequency rate " & vbCrLf
End If


Case Else
'handle any errors here

End Select

If Len(strMessage) = 0 Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
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
------------------------------------------------

Jeanette Cunningham




shiro said:
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





Hi all,
I have a subform in my form.The records I entered to subform seems
never
can be saved.When I check directly to subform's table,there is no any
record.
But if I entered the records directly to the forms while it's not
as a
subforms,
the data can be saved and I found it in my table.


What's the Subform's Recordsource property? Do you have any code on the
form
or the subform?

John W. Vinson [MVP]
 
S

shiro

Ms Jeanette,
About the main form,although the form get an error mesage but afterwards the
record still can be saved.

I remove all the code in the beforeupdate even of the form,and the record is
saved
normally.It mean there is something wrong with my code.But I can't see
it.How to
evaluate the code?.Trying to compile but didn't catch anything.

Jeanette Cunningham said:
Shiro,
Access can't save the main form record. That error 2115 says something about
a function - are there any functions that get called on the main form?
We can't fix the subform problem until we fix the main form.
I suggest that you remove the source object from the subform control so that
we can just get the main form to work by itself..
Save the main without the subform, run the form and check the errors.
If still an error, comment out all the code on the before update event, run
the form and see if it will save records.


Jeanette Cunningham


shiro said:
I trap the last three lines:

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

And get the error is:
Run time error 2115

And the VBA highlight the:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

But still can not find any records in my subform.





Jeanette Cunningham said:
Hi Shiro,
some part of the code in the before update event is causing an error.
This line
Forms![Revision spec_frm]![Spec
revisionhistory].Form![Remark_txt].SetFocus
is something I would never do in a before update event.
I would put that code in the after update event for the form.

Comment out that line and run the form.
If that doesn't help, you will need to test each section of the code below.
For example comment out the 6 lines below and run the form.
You have to keep checking until you find the bit of the code that is causing
the error.

If SpeedMode_opt.Value = 1 And _
Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

I would also change all the If - End If's to select case statement where
suitable.
see code below
----------------------------------------------------------

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

Select Case SpeedMode
Case >=1
If Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

If Freeaircurrentlolimit1.Value = 0 And _
Freeaircurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If
. . . . . . .
'you put in the rest of the other conditions here

Case 4
If DutyFreq_txt.Value = 0 Then
strMessage = strMessage & _
" Input Duty Frequency rate " & vbCrLf
End If


Case Else
'handle any errors here

End Select

If Len(strMessage) = 0 Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
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
------------------------------------------------

Jeanette Cunningham





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





Hi all,
I have a subform in my form.The records I entered to subform seems
never
can be saved.When I check directly to subform's table,there is no any
record.
But if I entered the records directly to the forms while it's not
as a
subforms,
the data can be saved and I found it in my table.


What's the Subform's Recordsource property? Do you have any code
on
the
form
or the subform?

John W. Vinson [MVP]
 
J

Jeanette Cunningham

Shiro,
I just noticed (should have spotted it before) that there is a line of code
to save the record.
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
The above line of code goes on the click event of the close button, never in
the before update event of the form.

Try this code for the before update event of your form
------------------------------------------------------------------------
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
Select Case SpeedMode
Case Is >= 1
If Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

If Freeaircurrentlolimit1.Value = 0 And _
Freeaircurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If

If Lockcurrentlolimit1.Value = 0 And _
Lockcurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Lock Current spec 1 " & vbCrLf
End If

Case 4
If DutyFreq_txt.Value = 0 Then
strMessage = strMessage & _
" Input Duty Frequency rate " & vbCrLf
End If

Case Else
'handle any errors here

End Select

If Len(strMessage) > 0 Then
Cancel = True
MsgBox strMessage, vbOKOnly, "Errors"
Else
End If

Case vbNo
If MsgBox("Cancel spec revision ? ", vbOKCancel, "Confirm") =
vbOK Then
Me.Undo
Cancel = True
End If

Case vbCancel
Cancel = True

End Select

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

End Sub

------------------------------------------------------------------------



shiro said:
Ms Jeanette,
About the main form,although the form get an error mesage but afterwards
the
record still can be saved.

I remove all the code in the beforeupdate even of the form,and the record
is
saved
normally.It mean there is something wrong with my code.But I can't see
it.How to
evaluate the code?.Trying to compile but didn't catch anything.

Jeanette Cunningham said:
Shiro,
Access can't save the main form record. That error 2115 says something about
a function - are there any functions that get called on the main form?
We can't fix the subform problem until we fix the main form.
I suggest that you remove the source object from the subform control so that
we can just get the main form to work by itself..
Save the main without the subform, run the form and check the errors.
If still an error, comment out all the code on the before update event, run
the form and see if it will save records.


Jeanette Cunningham


shiro said:
I trap the last three lines:

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

And get the error is:
Run time error 2115

And the VBA highlight the:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

But still can not find any records in my subform.





Hi Shiro,
some part of the code in the before update event is causing an error.
This line
Forms![Revision spec_frm]![Spec
revisionhistory].Form![Remark_txt].SetFocus
is something I would never do in a before update event.
I would put that code in the after update event for the form.

Comment out that line and run the form.
If that doesn't help, you will need to test each section of the code
below.
For example comment out the 6 lines below and run the form.
You have to keep checking until you find the bit of the code that is
causing
the error.

If SpeedMode_opt.Value = 1 And _
Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

I would also change all the If - End If's to select case statement where
suitable.
see code below
----------------------------------------------------------

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

Select Case SpeedMode
Case >=1
If Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

If Freeaircurrentlolimit1.Value = 0 And _
Freeaircurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If
. . . . . . .
'you put in the rest of the other conditions here

Case 4
If DutyFreq_txt.Value = 0 Then
strMessage = strMessage & _
" Input Duty Frequency rate " & vbCrLf
End If


Case Else
'handle any errors here

End Select

If Len(strMessage) = 0 Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
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
------------------------------------------------

Jeanette Cunningham





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





Hi all,
I have a subform in my form.The records I entered to subform seems
never
can be saved.When I check directly to subform's table,there is
no
any
record.
But if I entered the records directly to the forms while it's
not
as
a
subforms,
the data can be saved and I found it in my table.


What's the Subform's Recordsource property? Do you have any code on
the
form
or the subform?

John W. Vinson [MVP]
 
S

shiro

If Len(strMessage) > 0 Then
Cancel = True
MsgBox strMessage, vbOKOnly, "Errors"
Else
End If

From that function I place the 'Else' right after the If statement.
But I think it works fine.Cause the current condition will keep
the empty error messagebox although all fields have been filled.

And about the subform :
Is it initialized by 'there is no a relationship' between the mainform table
and the subform table datasource.

Cause currently,the PK of the mainform table datasource is connected
to another table with the referential integrity is turned on.




Jeanette Cunningham said:
Shiro,
I just noticed (should have spotted it before) that there is a line of code
to save the record.
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
The above line of code goes on the click event of the close button, never in
the before update event of the form.

Try this code for the before update event of your form
------------------------------------------------------------------------
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
Select Case SpeedMode
Case Is >= 1
If Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

If Freeaircurrentlolimit1.Value = 0 And _
Freeaircurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If

If Lockcurrentlolimit1.Value = 0 And _
Lockcurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Lock Current spec 1 " & vbCrLf
End If

Case 4
If DutyFreq_txt.Value = 0 Then
strMessage = strMessage & _
" Input Duty Frequency rate " & vbCrLf
End If

Case Else
'handle any errors here

End Select

If Len(strMessage) > 0 Then
Cancel = True
MsgBox strMessage, vbOKOnly, "Errors"
Else
End If

Case vbNo
If MsgBox("Cancel spec revision ? ", vbOKCancel, "Confirm") =
vbOK Then
Me.Undo
Cancel = True
End If

Case vbCancel
Cancel = True

End Select

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

End Sub

------------------------------------------------------------------------



shiro said:
Ms Jeanette,
About the main form,although the form get an error mesage but afterwards
the
record still can be saved.

I remove all the code in the beforeupdate even of the form,and the record
is
saved
normally.It mean there is something wrong with my code.But I can't see
it.How to
evaluate the code?.Trying to compile but didn't catch anything.

Jeanette Cunningham said:
Shiro,
Access can't save the main form record. That error 2115 says something about
a function - are there any functions that get called on the main form?
We can't fix the subform problem until we fix the main form.
I suggest that you remove the source object from the subform control so that
we can just get the main form to work by itself..
Save the main without the subform, run the form and check the errors.
If still an error, comment out all the code on the before update event, run
the form and see if it will save records.


Jeanette Cunningham


I trap the last three lines:

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

And get the error is:
Run time error 2115

And the VBA highlight the:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

But still can not find any records in my subform.





Hi Shiro,
some part of the code in the before update event is causing an error.
This line
Forms![Revision spec_frm]![Spec
revisionhistory].Form![Remark_txt].SetFocus
is something I would never do in a before update event.
I would put that code in the after update event for the form.

Comment out that line and run the form.
If that doesn't help, you will need to test each section of the code
below.
For example comment out the 6 lines below and run the form.
You have to keep checking until you find the bit of the code that is
causing
the error.

If SpeedMode_opt.Value = 1 And _
Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

I would also change all the If - End If's to select case statement where
suitable.
see code below
----------------------------------------------------------

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

Select Case SpeedMode
Case >=1
If Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

If Freeaircurrentlolimit1.Value = 0 And _
Freeaircurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If
. . . . . . .
'you put in the rest of the other conditions here

Case 4
If DutyFreq_txt.Value = 0 Then
strMessage = strMessage & _
" Input Duty Frequency rate " & vbCrLf
End If


Case Else
'handle any errors here

End Select

If Len(strMessage) = 0 Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
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
------------------------------------------------

Jeanette Cunningham





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





Hi all,
I have a subform in my form.The records I entered to subform seems
never
can be saved.When I check directly to subform's table,there is
no
any
record.
But if I entered the records directly to the forms while it's
not
as
a
subforms,
the data can be saved and I found it in my table.


What's the Subform's Recordsource property? Do you have any
code
on
the
form
or the subform?

John W. Vinson [MVP]
 
S

shiro

Solved it Ms Jeannette
The problem comes from also my subform code.
Excatly on the form BeforeUpdate even.
Thank's for the assist.

shiro said:
If Len(strMessage) > 0 Then
Cancel = True
MsgBox strMessage, vbOKOnly, "Errors"
Else
End If

From that function I place the 'Else' right after the If statement.
But I think it works fine.Cause the current condition will keep
the empty error messagebox although all fields have been filled.

And about the subform :
Is it initialized by 'there is no a relationship' between the mainform table
and the subform table datasource.

Cause currently,the PK of the mainform table datasource is connected
to another table with the referential integrity is turned on.




Jeanette Cunningham said:
Shiro,
I just noticed (should have spotted it before) that there is a line of code
to save the record.
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
The above line of code goes on the click event of the close button,
never
in
the before update event of the form.

Try this code for the before update event of your form
------------------------------------------------------------------------
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
Select Case SpeedMode
Case Is >= 1
If Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

If Freeaircurrentlolimit1.Value = 0 And _
Freeaircurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If

If Lockcurrentlolimit1.Value = 0 And _
Lockcurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Lock Current spec 1 " & vbCrLf
End If

Case 4
If DutyFreq_txt.Value = 0 Then
strMessage = strMessage & _
" Input Duty Frequency rate " & vbCrLf
End If

Case Else
'handle any errors here

End Select

If Len(strMessage) > 0 Then
Cancel = True
MsgBox strMessage, vbOKOnly, "Errors"
Else
End If

Case vbNo
If MsgBox("Cancel spec revision ? ", vbOKCancel, "Confirm") =
vbOK Then
Me.Undo
Cancel = True
End If

Case vbCancel
Cancel = True

End Select

Exit_Form_BeforeUpdate:
Exit Sub

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

End Sub

------------------------------------------------------------------------



shiro said:
Ms Jeanette,
About the main form,although the form get an error mesage but afterwards
the
record still can be saved.

I remove all the code in the beforeupdate even of the form,and the record
is
saved
normally.It mean there is something wrong with my code.But I can't see
it.How to
evaluate the code?.Trying to compile but didn't catch anything.

Shiro,
Access can't save the main form record. That error 2115 says something
about
a function - are there any functions that get called on the main form?
We can't fix the subform problem until we fix the main form.
I suggest that you remove the source object from the subform control so
that
we can just get the main form to work by itself..
Save the main without the subform, run the form and check the errors.
If still an error, comment out all the code on the before update event,
run
the form and see if it will save records.


Jeanette Cunningham


I trap the last three lines:

Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate

And get the error is:
Run time error 2115

And the VBA highlight the:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

But still can not find any records in my subform.





Hi Shiro,
some part of the code in the before update event is causing an error.
This line
Forms![Revision spec_frm]![Spec
revisionhistory].Form![Remark_txt].SetFocus
is something I would never do in a before update event.
I would put that code in the after update event for the form.

Comment out that line and run the form.
If that doesn't help, you will need to test each section of the code
below.
For example comment out the 6 lines below and run the form.
You have to keep checking until you find the bit of the code that is
causing
the error.

If SpeedMode_opt.Value = 1 And _
Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

I would also change all the If - End If's to select case statement
where
suitable.
see code below
----------------------------------------------------------

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

Select Case SpeedMode
Case >=1
If Rotationspeedlolimit1.Value = 0 And _
Rotationspeedhilimit1.Value = 0 Then
strMessage = strMessage & _
" Input RPM spec 1 " & vbCrLf
End If

If Freeaircurrentlolimit1.Value = 0 And _
Freeaircurrenthilimit1.Value = 0 Then
strMessage = strMessage & _
" Input Current spec 1 " & vbCrLf
End If
. . . . . . .
'you put in the rest of the other conditions here

Case 4
If DutyFreq_txt.Value = 0 Then
strMessage = strMessage & _
" Input Duty Frequency rate " & vbCrLf
End If


Case Else
'handle any errors here

End Select

If Len(strMessage) = 0 Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
Else
Cancel = True
MsgBox strMessage, vbOKOnly, "Errors"
End If

Case vbNo
If MsgBox("Cancel spec revision ? ", vbOKCancel,
"Confirm")
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





message
wrote:

Hi all,
I have a subform in my form.The records I entered to subform
seems
never
can be saved.When I check directly to subform's table,there is
no
any
record.
But if I entered the records directly to the forms while it's
not
as
a
subforms,
the data can be saved and I found it in my table.


What's the Subform's Recordsource property? Do you have any code
on
the
form
or the subform?

John W. Vinson [MVP]
 
J

John W. Vinson

Shiro,
I just noticed (should have spotted it before) that there is a line of code
to save the record.

Thanks for jumping in, Jeanette! I got busy and a bit overwhelmed by Shiro's
code. I really appreciate the rescue!!


John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top