Search code examples
vbams-access

Insert textbox value from a form into a table


I have a textbox(in form) and a field(in table) both named SerialNumber

This is the control source of the textbox: =([OrderNr] & (""+[Aantal]) & "" & [SapArtNr])

I can't seem to make the textbox save the value inside into the table.

Edit:

Option Compare Database

Private Sub Command82_Click()
    ' Add data to Table
    CurrentDb.Execute "INSERT INTO Geleidelijst(SerialNmbr, InvoerOrderNr, InvoerAantal, InvoerVermogen, InvoerHSLSSpn) " & _
            " VALUES(" & Me.SerialNumberLong & ",'" & Me.OrderNr & "','" & _
            Me.Aantal & "','" & Me.Vermogen & "','" & Me.HSLSSpn & "')"
End Sub

But then I get error: 3075 Synax error missing operating in query expression. And if I add date as a format it doesn't work either.

Only when it's numbers, but when there's letters and dots and "/" for example, it won't work.

Any help would be nice, thanks.


Solution

  • Most likely, Aantal is numeric, so try without quotes:

    CurrentDb.Execute "INSERT INTO Geleidelijst " & _
        "(SerialNmbr, InvoerOrderNr, InvoerAantal, InvoerVermogen, InvoerHSLSSpn) " & _
        "VALUES('" & Me.SerialNumberLong & "','" & Me.OrderNr & "'," & Me.Aantal & ",'" & Me.Vermogen & "','" & Me.HSLSSpn & "')"