Results 1 to 2 of 2
  1. #1
    Blitz is offline Novice
    Windows 7 32bit Access 2002
    Join Date
    Nov 2012
    Posts
    2

    AddNew does not create record and gives no error...

    Hi,



    I'm creating a recordset like this:

    Dim q As Recordset
    Set q = CurrentDb.OpenRecordset("SELECT * FROM TabelDone WHERE Datum=" & !datum)

    in direct window, I see that !datum effectively holds a valid date (comes from another recordset)
    I check my tabeldone table, and the record with the specified date is there...

    in direct window, print q.recordcount results in zero.

    Adding a record to q (q.addnew) does not give an error, but... print q.recordcount results in zero again.

    I got this far after VB had given me the error that (after q.addnew), there was no current record.
    I assumed I had forgotten to q.edit, but that doesn't help either.

    How do I add a record to q?

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Set q = CurrentDb.OpenRecordset("SELECT * FROM TabelDone WHERE Datum=" & !datum)
    I have never seen this type of syntax. Usually it is "Me.datum" or Forms!FormName!datum or Forms!FormName.datum
    (Maybe you could use it inside a With ... End With block)

    Code:
    Set q = CurrentDb.OpenRecordset("SELECT * FROM TabelDone WHERE Datum = " & Me.datum)
    Set q = CurrentDb.OpenRecordset("SELECT * FROM TabelDone WHERE Datum = " & Forms!FormName!datum)
    Set q = CurrentDb.OpenRecordset("SELECT * FROM TabelDone WHERE Datum = " & Forms!FormName.datum)
    
    (change FormName to your form name)

    If you want to see if there are in fact records for a datum = 4, then try

    Code:
    Set q = CurrentDb.OpenRecordset("SELECT * FROM TabelDone WHERE Datum =  4 ")
    and check q.recordcount.

    If you use the above syntax, "WHERE Datum = 4", and add a record using

    Code:
    Dim q As DAO.Recordset
    Set q = CurrentDb.OpenRecordset("SELECT * FROM TabelDone WHERE Datum=4")
    q.AddNew
    q!datum = 7
    q.update
    q.requery
    If you then check the recordcount ,q.RecordCount will not reflect the newly added record because datum = 7 (and not 4)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Update or CancelUpdate without AddNew or Edit
    By westcoastbmx in forum Forms
    Replies: 5
    Last Post: 11-07-2019, 09:01 PM
  2. Replies: 5
    Last Post: 08-21-2012, 12:30 PM
  3. Replies: 22
    Last Post: 06-12-2012, 10:02 PM
  4. Using Recordset rst.AddNew
    By dandoescode in forum Programming
    Replies: 1
    Last Post: 06-06-2012, 10:10 AM
  5. How to code in AddNew Button In Access DBA
    By ganeshvenkatram in forum Access
    Replies: 0
    Last Post: 07-07-2011, 02:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums