PDA

Click to See Complete Forum and Search --> : records not writing to table


Jul 19th, 1999, 09:33 PM
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

preeti
Jul 19th, 1999, 10:06 PM
Hi,

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

Preeti

Jul 19th, 1999, 10:50 PM
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?

Jul 20th, 1999, 01:33 AM
thankx preeti,

that did it...now it works!

ever grateful,
larryn

preeti
Jul 20th, 1999, 11:59 AM
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