Results 1 to 5 of 5

Thread: records not writing to table

  1. #1
    Guest

    Post

    why doesn't this code work?
    there is one textbox where a number is entered and then i want to write that number and date and time and another date to table.


    Private Sub txtOrdNo_AfterUpdate()
    Dim db As Database
    Dim rs As Recordset

    Set db = CurrentDb
    Set rs = db.OpenRecordset("Billing_Audit", dbOpenTable)

    While Not rs.EOF
    rs.AddNew
    rs("Invoice_Date") = Me.txtDate
    rs("Order_No") = Me.txtOrdNo
    rs("Date_Scanned") = Format(Now, "yyyymmdd")
    rs("Time_Scanned") = Format(Now, "hhnnss")
    rs.Update
    Wend
    End Sub



  2. #2
    Lively Member
    Join Date
    Jan 1999
    Posts
    82

    Post

    Hi,

    What happens when you try to run this code? Are there any error messages or anything?

    Preeti


  3. #3
    Guest

    Post

    runtime error 3022:
    changes you requested weren't successful because they would create duplicate values in the index, primary key, etc...

    the i click debug and
    rs.Update
    is highlighted

    any thoughts?

  4. #4
    Guest

    Post

    thankx preeti,

    that did it...now it works!

    ever grateful,
    larryn

  5. #5
    Lively Member
    Join Date
    Jan 1999
    Posts
    82

    Post

    Hi,

    The field that you have declared as your primary key can only have one instance of a value. You are trying to add an existing value into your database.

    Put a watch on the value that is going into your primary key field and see if the value you are trying to insert already exists in the database.

    Also, remove the while loop. I am assuming that you are tyring to insert this record only once so you do not need to keep on inserting until you reach the end of the table.

    HTH,

    Preeti

Posting Permissions

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



Click Here to Expand Forum to Full Width