Problem with sql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rockhound
    New Member
    • Jan 2011
    • 2

    #1

    Problem with sql

    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 = ""
        Total_v.Value = ""
        Um.Value = ""
        
    End If
    DoCmd.Close
    ------------------------------------
    Im getting runtime error 3061 too few parameters , expected 1

    I think the problem is somewhere in the select statement
    Last edited by Stewart Ross; Jan 13 '11, 07:36 PM. Reason: Added code tags
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    It usually means an incorrect field name.
    A common error is field names with spaces.
    Wrap the field names in square brackets []

    Comment

    • mshmyob
      Recognized Expert Contributor
      • Jan 2008
      • 903

      #3
      I'll take a wild stab here based on what you posted.

      Your INSERT sql string has no space between your columns and Values.

      Try

      Code:
      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));"

      cheers,

      Comment

      • Rockhound
        New Member
        • Jan 2011
        • 2

        #4
        @mshmyob
        i don't see any difference between my string and what you wrote ,i may be mistaking though

        Comment

        • mshmyob
          Recognized Expert Contributor
          • Jan 2008
          • 903

          #5
          I put in a space before the word VALUES - you need a space.

          Also I assume in your actual code you have conconated the 1st and 2nd line - since it is not how it is displayed here.

          cheers,

          Comment

          Working...