Help with Runtime Error 2118

E

EAB1977

Hello all,

I have on a form with a unbound combo box called cboSupplier that a
user can either type in the Supplier or select it from a drop down box.
Most of my users will type in the name. If the name they type is not in
the drop down list, it fires off the NotInList event. From there, I ask
my users if they want to add the information to the dropdown list. If
the user clicks yes, another form opens (frmSuppliers) and then the
user will type in as much information as they can (address, city,
state, zip, phone number). When the user tries to save the form and
requery the listbox, I get a error 2118 that says that they must save
the current record before the requery action will run.

In my code, I already save it to the table, so why am I getting this
error? Code is below:

Private Sub cboSupplier_NotInList(NewData As String, Response As
Integer)
Dim msg1 As Integer

Response = acDataErrContinue
msg1 = MsgBox("The Supplier you selected is not in the dropdown
list. Do you wish to enter in the Supplier information?", vbYesNo +
vbQuestion)
If msg1 = vbYes Then
DoCmd.OpenForm "frmSuppliers"
Else
Me.cboSupplier.Value = ""
Me.cboSupplier.SetFocus
Me.cboSupplier.Dropdown
End If
End Sub

------------------------------------------------------------------------------------------------------
The next part of the code is from the frmSuppliers_btnSaveClick action:

Private Sub btnSave_Click()
Dim db As Database, rstSupp As Recordset

On Error GoTo Err_btnSave_Click

Set db = CurrentDb
Set rstSupp = db.OpenRecordset("tblSuppliers")

With rstSupp
.AddNew
!SupplierName = Me.txtSupplierName.Value
!ContactName = Me.txtContactName.Value
!Address = Me.txtAddress.Value
!City = Me.txtCity.Value
!State = Me.txtState.Value
!Zip = Me.txtZip.Value
!PhoneNumber = Me.txtPhoneNumber.Value
.Update
.Close
End With

Forms!frmProductInformation!cboSupplier.Requery <---- bombs here
DoCmd.Close acForm, Form.Name

Exit_btnSave_Click:
Set rstSupp = Nothing
Set db = Nothing
Exit Sub

Err_btnSave_Click:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_btnSave_Click

End Sub

------------------------------------------------
The Form's Load Event:

Private Sub Form_Load()
If fIsLoaded("frmProductInformation") Then
Me.txtSupplierName.Value =
Forms!frmProductInformation!cboSupplier.Text
End If
End Sub
 
G

Guest

Just a guess on my part, but you might need to clear whatever the user typed
into cboSupplier, or reset it somehow before requerying it.
 

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

Similar Threads


Top