Error '3251'

Loic_7447 Posted messages 32 Registration date   Status Membre Last intervention   -  
f894009 Posted messages 17417 Registration date   Status Membre Last intervention   -
Hello everyone,

I created a form to add rows to a table in my database.

Among these rows, there is a field called "Supplier."
I want that when someone enters a supplier that does not yet exist in the database, they are directed to another form to enter the information for this new supplier.

To do this, I typed this code (integrated into the main code of the form):
Set rsref = db.OpenRecordset("tFournisseurs") rsref.FindFirst ("Supplier='" + CStr(Me.txt_fournisseur) + "'") If rsref.NoMatch Then MsgBox ("Supplier not registered, You will be directed to the add page") DoCmd.OpenForm ("fAdd_Supplier") End If


Small problem, it shows me this message: "Runtime error '3251': Operation not allowed for this type of object."
The debugger indicates line 2 (
rsref.findfirst...
).

Here is the full code:
Option Compare Database Option Explicit Private Sub btn_add_Click() Dim db As DAO.Database Dim rs As DAO.Recordset Dim rsref As DAO.Recordset Set db = CurrentDb Set rs = db.OpenRecordset("#tStock_search") If Me.txt_reference = "" Or Me.txt_supplier = "" Or Me.txt_quantity = "" _ Or Me.txt_tool = "" Or Me.txt_sector = "" Or Me.txt_location = "" Then MsgBox ("Please fill in all fields") Else rs.AddNew rs!Reference = Me.txt_reference rs!Supplier = Me.txt_supplier rs!Quantity = Me.txt_quantity rs!Type = Me.txt_tool rs!Sector = Me.txt_sector rs!Location = Me.txt_location rs.Update MsgBox ("Reference added successfully") txt_reference = "" txt_supplier = "" txt_quantity = "" txt_tool = "" txt_sector = "" txt_location = "" End If Set rsref = db.OpenRecordset("tSuppliers") rsref.FindFirst ("Supplier='" + CStr(Me.txt_supplier) + "'") If rsref.NoMatch Then MsgBox ("Supplier not registered, You will be directed to the add page") DoCmd.OpenForm ("fAdd_Supplier") End If rs.Close rsref.Close db.Close DoCmd.OpenForm ("#fDetail_tool") Set rs = Nothing Set db = Nothing Set rsref = Nothing End Sub


I hope you can help me solve this problem!

2 réponses

f894009 Posted messages 17417 Registration date   Status Membre Last intervention   1 717
 
Hello,

I tested your syntax, no errors!

Next:
I have the error, but I would need your file to confirm
0
Loic_7447 Posted messages 32 Registration date   Status Membre Last intervention  
 
I'm sorry, but I can't access external links. Please provide the text you want translated directly here.
0
f894009 Posted messages 17417 Registration date   Status Membre Last intervention   1 717
 
Hello,

Please avoid leaving the text boxes empty before using them!

 If Me.txt_reference = "" Or Me.txt_fournisseur = "" Or Me.txt_quantité = "" _ Or Me.txt_outil = "" Or Me.txt_secteur = "" Or Me.txt_emplacement = "" Then MsgBox ("Please fill in all fields") Else rs.AddNew rs!Référence = Me.txt_reference rs!Fournisseur = Me.txt_fournisseur rs!Quantité = Me.txt_quantité rs!Type = Me.txt_outil rs!Secteur = Me.txt_secteur rs!Emplacement = Me.txt_emplacement rs.Update MsgBox ("Reference successfully added") ' RESET HERE txt_reference = "" txt_fournisseur = "" txt_quantité = "" txt_outil = "" txt_secteur = "" txt_emplacement = "" End If Set rsref = db.OpenRecordset("tFournisseurs") rsref.FindFirst ("Fournisseur='" + CStr(Me.txt_fournisseur) + "'") 'thus error 
0