S
SA
Hello everyone. I have the following code. I am using only one table
(tempTable) and a form (tempForm) to add record to the table using AddNew
method. I have placed this code on ‘on click’ event of a command button
(cmdSave_Click())
Private Sub cmdSave_Click()
Dim rs As ADODB.Recordset
On Error GoTo HandleError
Set rs = New ADODB.Recordset
rs.Open “tempTableâ€, CurrentProject.Connection, _
adOpenDynamic, adLockOptimistic
With rs
.AddNew
![Qty] = Qty
.Update
End With
rs.Close
Set rs = Nothing
ExitHere:
Exit Sub
HandleError:
MsgBox Err.Description
Resume ExitHere
End Sub
Now the problem is:
1.When I enter value of Qty on the form and click the button to save it on
the table, it creates duplicate values in a strange way. After clicking the
button, if I open the table to see if data is posted keeping the form open,
it shows single record as it should be. But when I close the form and refresh
the table clicking refresh button or reopen the table it duplicates the value.
2.If I hard code the value of Qty like Qty = “100â€, the code works just
fine. But when you replace the value with ![Qty] = Qty, then is the problem.
For testing this further, I added a line Qty = Ҡafter .Update to see what
happens. In this case, I found the same duplicate effect but first record is
blank, only Id has the autonumber value.
How can I use the .AddNew method properly so that I can get the desired
result?
Another question, if I want to use .bookmark on record, how can I use it? As
if I use it like .BookMark = .LastModified after .upadate, it generates an
error message saying “Method or Data Member not foundâ€.
Can anyone please help me on this?
Thanks in advance. 
(tempTable) and a form (tempForm) to add record to the table using AddNew
method. I have placed this code on ‘on click’ event of a command button
(cmdSave_Click())
Private Sub cmdSave_Click()
Dim rs As ADODB.Recordset
On Error GoTo HandleError
Set rs = New ADODB.Recordset
rs.Open “tempTableâ€, CurrentProject.Connection, _
adOpenDynamic, adLockOptimistic
With rs
.AddNew
![Qty] = Qty
.Update
End With
rs.Close
Set rs = Nothing
ExitHere:
Exit Sub
HandleError:
MsgBox Err.Description
Resume ExitHere
End Sub
Now the problem is:
1.When I enter value of Qty on the form and click the button to save it on
the table, it creates duplicate values in a strange way. After clicking the
button, if I open the table to see if data is posted keeping the form open,
it shows single record as it should be. But when I close the form and refresh
the table clicking refresh button or reopen the table it duplicates the value.
2.If I hard code the value of Qty like Qty = “100â€, the code works just
fine. But when you replace the value with ![Qty] = Qty, then is the problem.
For testing this further, I added a line Qty = Ҡafter .Update to see what
happens. In this case, I found the same duplicate effect but first record is
blank, only Id has the autonumber value.
How can I use the .AddNew method properly so that I can get the desired
result?
Another question, if I want to use .bookmark on record, how can I use it? As
if I use it like .BookMark = .LastModified after .upadate, it generates an
error message saying “Method or Data Member not foundâ€.
Can anyone please help me on this?
Thanks in advance.