Problem locating record using a combobox in a subform

G

Guest

I really need help on this one...

Im having a problem trying to locate a record in a subform. This error keeps
recurring when I try to add a new entry in a combo box. Heres the situation:

I have a subform inside a report form. On the report form, there is a combo
box for the list of the models. Whenever I choose a model not inside the
list, it adds a new record inside the model subform. However, when I try to
edit the fields inside the subform, this error occurs...

The Microsoft Jet Database Engine cannot find a record in the table 'Model
Data' with key matching field(s) 'ModelID'

When I check the new model in the model table, the new model is added, but
the error message keeps prompting. Why is this happening?

Heres the code:

Private Sub cboModelID_AfterUpdate()
On Error GoTo Err_cboModelID_AfterUpdate

Dim rs As DAO.Recordset
Dim rs1 As Object

If Me.cboModelID.ListIndex = -1 Then
If MsgBox("Add Model " & Me.cboModelID & " ?", vbQuestion + vbYesNo,
"Add new name?") = vbYes Then
Set rs = Me.[Calibration CertDetails Model
Subform].Form.RecordsetClone
On Error Resume Next
rs.AddNew
rs!ModelID = Me.cboModelID
rs.Update
Set rs = Nothing
DoEvents
End If
End If

Set rs1 = Me.[Calibration CertDetails Model Subform].Form.RecordsetClone
rs1.FindFirst "[ModelID] = '" & Me![cboModelID] & "'"
If Not rs1.EOF Then
Me.[Calibration CertDetails Model Subform].Form.Bookmark =
rs1.Bookmark
Me.[Calibration CertDetails Model Subform].Form.Visible = True
End If

Exit_cboModelID_AfterUpdate:
Exit Sub

Err_cboModelID_AfterUpdate:
MsgBox "Subroutine Error: Unable to Access Model Data."
Resume Exit_cboModelID_AfterUpdate

End Sub

How do I solve this? Thanks in advance.
 

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