PDA

View Full Version : help with insert INTO



kenzo
12-11-2018, 01:17 PM
I've made a form with some buttons
Now on every click on a button, I use the name of the button, to insert that into a table
But my syntax won't work.... what's wrong with it .... 23391

This is the code I use :


Private Sub JUPILER_Click()


Dim artikelnummer As Integer
Dim drank As String: drank = Me.ActiveControl.Name
MsgBox ("naam van het artikel = " & drank)


artikelnummer = DLookup("[ID]", "tbl_artikelen", "ucase([omschrijving]) ='" & drank & "'")
MsgBox (drank & " heeft als artikelnummer " & artikelnummer)
' gegevens in tabel ingeven
Dim db As Database
Dim rec As Recordset


Set db = CurrentDb
Set rec = db.OpenRecordset("Select * from tbl_bestelbon")


rec.AddNew
rec("omschrijving") = artikelnummer
rec("aantal") = 1
rec.Update


Set rec = Nothing
Set db = Nothing
End Sub




It doesn't give me an error ...
but there is no new record.

What am I doing wrong?
tnx for your advice

OBP
12-12-2018, 05:37 AM
The normal code for editing a record's field is like this
rec!omschrijving = artikelnummer
rec!aantal = 1
or
rec.omschrijving = artikelnummer
rec.aantal = 1

It is also possible because you do not end your Addnew code with
rec.Bookmark = .LastModified

kenzo
12-12-2018, 05:44 AM
The normal code for editing a record's field is like this
rec!omschrijving = artikelnummer
rec!aantal = 1
or
rec.omschrijving = artikelnummer
rec.aantal = 1

It is also possible because you do not end your Addnew code with
rec.Bookmark = .LastModified

OK, thx, I already tried a lot and I found it already


Dim db As Database
Set db = CurrentDb
Dim bestelbonregel As Recordset


Set bestelbonregel = db.OpenRecordset("tbl_bestelbon")
With bestelbonregel
.AddNew
!datum = datum
!omschrijving = artikelnummer
!aantal = 1
.Update
.Bookmark = .LastModified
End With


as you said with the bookmark, it worked