I am a first time poster on here, but have used this site regularly as a great resource to help me find answers to questions other folks have already asked. This time... I need help finding the problem in my own code.
Backstory: I have an Access 2003 mdb front end connected to a similar back end. I am working on a form to handle checking in samples. The main form contains general information about the chain of custody. The form contains a tabbed control. On each tab I have a subform. On the tab "Check-In" the subform (frmSampleCheckinSubform2) is used to handle sample information. It also contains a subform (frmSampleCheckinSubform21) which is used to handle subsample information. Simple enough. For ease I will call these subforms subform2 and subform21 respectively.
Subform2 contains 2 unbound buttons, "New Sample" (cmdNEwSample), "Delete Sample" (cmdDeleteSample) and an unbound checkbox "Duplicate Fields" (chkDupFields).
Open the form for a new sample...
-adding a sample works like a charm
-deleting a sample works like a charm
The problem: If you delete all the samples, then by choosing either the chkbox or the new sample button, I get a vague "No current record" error. I am assuming that this is happening because some control is trying to refernce the record when the recordset has been totally deleted. I however cannot find it.
What I've done: I have attached the code for both the "New Sample" and "Delete Sample" button. I have tried adding stop points within all the code to narrow down the statement that is generating the error. I can't find it. It appears to be happening between the time the Delete Sample code finished and before the first statement in the "new sample" code.
Suggestions?
Thanks for any and all help with this problem.
Delete Button Code:
New Sample Code:
Backstory: I have an Access 2003 mdb front end connected to a similar back end. I am working on a form to handle checking in samples. The main form contains general information about the chain of custody. The form contains a tabbed control. On each tab I have a subform. On the tab "Check-In" the subform (frmSampleCheckinSubform2) is used to handle sample information. It also contains a subform (frmSampleCheckinSubform21) which is used to handle subsample information. Simple enough. For ease I will call these subforms subform2 and subform21 respectively.
Subform2 contains 2 unbound buttons, "New Sample" (cmdNEwSample), "Delete Sample" (cmdDeleteSample) and an unbound checkbox "Duplicate Fields" (chkDupFields).
Open the form for a new sample...
-adding a sample works like a charm
-deleting a sample works like a charm
The problem: If you delete all the samples, then by choosing either the chkbox or the new sample button, I get a vague "No current record" error. I am assuming that this is happening because some control is trying to refernce the record when the recordset has been totally deleted. I however cannot find it.
What I've done: I have attached the code for both the "New Sample" and "Delete Sample" button. I have tried adding stop points within all the code to narrow down the statement that is generating the error. I can't find it. It appears to be happening between the time the Delete Sample code finished and before the first statement in the "new sample" code.
Suggestions?
Thanks for any and all help with this problem.
Delete Button Code:
Code:
Private Sub cmdDeleteSample_Click()
On Error GoTo Err_cmdDeleteSample_Click
If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "Delete Record?") = vbYes Then
'DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
'DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSelectRecord 'this command is not normally needed
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
'Me.Requery
Me.AllowAdditions = False
End If
Exit_cmdDeleteSample_Click:
Exit Sub
Err_cmdDeleteSample_Click:
MsgBox Err.Number & ": " & Err.Description, , Me.Name
Resume Exit_cmdDeleteSample_Click
End Sub
New Sample Code:
Code:
Private Sub cmdNewSample_Click()
On Error GoTo Err_cmdNewSample_Click
Dim o_LabProjectID, o_Type, o_SampleDate, o_BeginCompositeDate, o_CollectionMethod, o_Collector, o_Containers
Dim o_ContType, o_Preservation, o_TurnAround, o_StationID, o_Replicate, o_SamplePoint, o_Investigators, o_Reason, o_SampleInfo_COCID
Dim o_ShippedTo, o_ShipmentMethod, o_comments, o_Samples, o_SampleCount
'Check if recordset is empty and if not duplicate fields
If Me.Recordset.RecordCount = 0 Then Me.ChkDupFields = 0
If Me.Parent!cboProject = 0 Then
MsgBox "You must select the Project First", , "Select Project"
Cancel = True
Me.Parent!cboProject.SetFocus
Else
If Me.ChkDupFields = -1 Then
'check if a current record
'Save current Record
If Me.Dirty Then Me.Dirty = False
Me.AllowAdditions = True
'get current values current records
o_LabProjectID = Me.[Lab Project ID]
o_Type = Me.Type
o_SampleDate = Me.SampleDate
o_BeginCompositeDate = Me.BeginCompositeDate
o_CollectionMethod = Me.CollectionMethod
o_Collector = Me.Collector
o_Containers = Me.Containers
o_ContType = Me.ContType
o_Preservation = Me.Preservation
o_TurnAround = Me.TurnAround
o_StationID = Me.StationID
o_Replicate = Me.Replicate
o_SamplePoint = Me.SamplePoint
o_Investigators = Me.Investigators
o_Reason = Me.Reason
o_SampleInfo_COCID = Me.txtCOCSampleInfoCOCID
o_ShippedTo = Me.ShippedTo
o_ShipmentMethod = Me.ShipmentMethod
o_comments = Me.Comments
o_Samples = Me.Samples
o_SampleCount = Me.SampleCount
'Create new Primary Record
If Not Me.NewRecord Then
DoCmd.GoToRecord , , acNewRec
End If
'add default values
Me.txtContainers = 1
Me.SampleCount = 1
Me.Samples = Me.txtSampleInfoSampleID
Me.txtLabProjectID = Me.Parent.Form.ProjectID
Me.txtCOCSampleInfoSampleID = Me.txtSampleInfoSampleID
'add cloned record values
Me.[Lab Project ID] = o_LabProjectID
Me.Type = o_Type
Me.SampleDate = o_SampleDate
Me.BeginCompositeDate = o_BeginCompositeDate
Me.CollectionMethod = o_CollectionMethod
Me.Collector = o_Collector
Me.Containers = o_Containers
Me.ContType = o_ContType
Me.Preservation = o_Preservation
Me.TurnAround = o_TurnAround
Me.StationID = o_StationID
Me.Replicate = o_Replicate
Me.SamplePoint = o_SamplePoint
Me.Investigators = o_Investigators
Me.Reason = o_Reason
Me.txtCOCSampleInfoCOCID = o_SampleInfo_COCID
Me.ShippedTo = o_ShippedTo
Me.ShipmentMethod = o_ShipmentMethod
Me.Comments = o_comments
Me.Samples = o_Samples
Me.SampleCount = o_SampleCount
If Me.Dirty Then Me.Dirty = False
Me.AllowAdditions = False
'add new subsample too
Me.frmSampleCheckInSubform21.SetFocus
Me.frmSampleCheckInSubform21.Form.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
Me!frmSampleCheckInSubform21.Form.Subsample = 1
Me!frmSampleCheckInSubform21.Form.txtSubandSample = Trim(Str(Me.txtSampleInfoSampleID) + "-" + Chr$(64 + Me!frmSampleCheckInSubform21.Form.Subsample))
Me.frmSampleCheckInSubform21.Form.AllowAdditions = False
Else
'Add new Record
Me.AllowAdditions = True
If Not Me.NewRecord Then
DoCmd.GoToRecord , , acNewRec
End If
Me.txtContainers = 1
Me.SampleCount = 1
Me.Samples = Me.txtSampleInfoSampleID
Me.txtLabProjectID = Me.Parent.Form.ProjectID
Me.txtCOCSampleInfoSampleID = Me.txtSampleInfoSampleID
If Me.Dirty Then Me.Dirty = False
Me.AllowAdditions = False
'add new subsample to
Me.frmSampleCheckInSubform21.SetFocus
Me.frmSampleCheckInSubform21.Form.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
Me!frmSampleCheckInSubform21.Form.Subsample = 1
Me!frmSampleCheckInSubform21.Form.txtSubandSample = Trim(Str(Me.txtSampleInfoSampleID) + "-" + Chr$(64 + Me!frmSampleCheckInSubform21.Form.Subsample))
Me.frmSampleCheckInSubform21.Form.AllowAdditions = False
End If
End If
Exit_cmdNewSample_Click:
Exit Sub
Err_cmdNewSample_Click:
If Err.Number <> 2499 Or Err.Number <> 3167 Then
MsgBox Err.Number & ": " & Err.Description, , Me.Name
Resume Exit_cmdNewSample_Click
End If
End Sub