Problem with sql

DeletedUser

Guest
Code:
Private Sub btnAdaugare_Click()

Dim rs As Recordset

Set rs = CurrentDb.OpenRecordset( _
"SELECT * FROM Factura_Emisa where Serie_Nr_Factura =" & Serienr.Value, dbOpenDynaset, dbReadOnly)

If rs.RecordCount > 0 Then
MsgBox ("Factura existenta in baza de date !")
Else
sql = "INSERT INTO Factura_Emisa (CIF_Client,Denumire_Client,Serie_Nr_Factura,Adresa_Client,Cantitate,Pret,
Valoare_Fara_Tva,Valoare_Tva,Cota_Tva,Total_Valoare,Um)" & _
"VALUES (UCase(Trim(CIF.Value))," & _
"UCase(Trim(Serienr.Value))," & _
"Trim(Cantitate.Value)," & _
"Trim(Pret.Value)," & _
"Trim(Valoaref.Value)," & _
"Trim(tva.Value)," & _
"Trim(Cota.Value)," & _
"Trim(Total_v.Value)," & _
"Trim(UM.Value))"

DoCmd.RunSQL sql

MsgBox ("Factura a fost operata in baza de date !")

Denumire_Client.Value = ""
CIF.Value = ""
adrs.Value = ""
Serienr.Value = ""
Cantitate.Value = ""
Pret.Value = ""
Valoaref.Value = ""
tva.Value = ""
Cota.Value = ""
Ttoal_v.Value = ""
Um.Value = ""

End If
DoCmd.Close


End Sub
-------------------------------------------------------------------
"Runtime error 3061 to few parameters , Expected 1"


Hope someone can help me with this
 
Last edited by a moderator:

DeletedUser5

Guest
I've found the problem in your code.

That error means that there is a syntax error in your SQL statement.

Look at the following piece of code...
Code:
Set rs = CurrentDb.OpenRecordset( _
"SELECT * FROM Factura_Emisa where Serie_Nr_Factura =" & Serienr.Value, dbOpenDynaset, dbReadOnly)

And change it to the following...

Code:
Set rs = CurrentDb.OpenRecordset( _
"SELECT * FROM Factura_Emisa where Serie_Nr_Factura ='" & Serienr.Value & "'", dbOpenDynaset, dbReadOnly)

I can't see any other errors in your code, so give that a whirl and see if it works.
 

DeletedUser

Guest
I am not an expert in VB code, (I hate it! lol) but you appear to have 10 fields to place values into in your INSERT statement, and ony 9 values?

Does the line number match the INSERT or the SELECT?
 

DeletedUser5

Guest
I am not an expert in VB code, (I hate it! lol) but you appear to have 10 fields to place values into in your INSERT statement, and ony 9 values?

Does the line number match the INSERT or the SELECT?

You're correct, 11 columns (not 10), and only 9 values.
 
Top