Consulting

Results 1 to 3 of 3

Thread: help with insert INTO

  1. #1
    VBAX Newbie
    Joined
    Aug 2016
    Posts
    3
    Location

    help with insert INTO

    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 .... kassatabelvba.JPG

    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

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    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

  3. #3
    VBAX Newbie
    Joined
    Aug 2016
    Posts
    3
    Location
    Quote Originally Posted by OBP View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •