If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Where are my subform records..
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. |
#2
|
|||
|
|||
Where are my subform records..
On Sun, 6 Jan 2008 11:07:31 +0700, "shiro" 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] |
#3
|
|||
|
|||
Where are my subform records..
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" wrote in message ... On Sun, 6 Jan 2008 11:07:31 +0700, "shiro" 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] |
#4
|
|||
|
|||
Where are my subform records..
"shiro" wrote in message ... 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" wrote in message ... On Sun, 6 Jan 2008 11:07:31 +0700, "shiro" 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] |
#5
|
|||
|
|||
Where are my subform records..
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" wrote in message ... "shiro" wrote in message ... 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" wrote in message ... On Sun, 6 Jan 2008 11:07:31 +0700, "shiro" 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] |
#6
|
|||
|
|||
Where are my subform records..
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" wrote in message ... 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" wrote in message ... "shiro" wrote in message ... 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" wrote in message ... On Sun, 6 Jan 2008 11:07:31 +0700, "shiro" 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] |
#7
|
|||
|
|||
Where are my subform records..
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" wrote in message ... 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" wrote in message ... 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" wrote in message ... "shiro" wrote in message ... 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" wrote in message ... On Sun, 6 Jan 2008 11:07:31 +0700, "shiro" 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] |
#8
|
|||
|
|||
Where are my subform records..
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" wrote in message ... 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" wrote in message ... 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" wrote in message ... 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" wrote in message ... "shiro" wrote in message ... 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" wrote in message ... On Sun, 6 Jan 2008 11:07:31 +0700, "shiro" 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] |
#9
|
|||
|
|||
Where are my subform records..
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" wrote in message ... 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" wrote in message ... 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" wrote in message ... 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" wrote in message ... 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" wrote in message ... "shiro" wrote in message ... 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" wrote in message ... On Sun, 6 Jan 2008 11:07:31 +0700, "shiro" 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] |
#10
|
|||
|
|||
Where are my subform records..
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" wrote in message ... 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" wrote in message ... 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" wrote in message ... 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" wrote in message ... 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" wrote in message ... 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" wrote in message ... "shiro" wrote in message ... 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" wrote in message ... On Sun, 6 Jan 2008 11:07:31 +0700, "shiro" 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] |
|
Thread Tools | |
Display Modes | |
|
|