L'apprentis
Redcifer
- Local time
- Today, 13:38
- Joined
- Jun 22, 2005
- Messages
- 177
This is the code i am trying to use to add a record in one of my table.
This is not working properly, the data are not added in the table and if I add a value directly in the table I can notice that the autonumber is incremented by the number of time I have pressed the button. It is like all the data are successfully entered and erased as soon as I press the command button.
I was wondering if anybody could see anything wrong in the code?
This is not working properly, the data are not added in the table and if I add a value directly in the table I can notice that the autonumber is incremented by the number of time I have pressed the button. It is like all the data are successfully entered and erased as soon as I press the command button.
I was wondering if anybody could see anything wrong in the code?
Code:
Private Sub CmdAddLine_Click()
On Error GoTo Err_CmdAddLine_Click
' connection and recordset object variables
Dim cn As Connection
Dim Rs As ADODB.Recordset
' open a connection to the connection object
Set cn = CurrentProject.Connection
' initialise the recordset object
Set Rs = New ADODB.Recordset
' using the recordset object
With Rs
.Open "TblLineConfig", cn, adOpenStatic, adLockPessimistic ' open it
.AddNew 'Prepare to add new record
.Fields("LineID") = Forms!FrmDrawing!CboDimLine.Column(0)
.Fields("LineQty") = Forms!FrmDrawing!TxtLineQty
.Fields("DrawingID") = Forms!FrmDrawing!TxtDrawingID
.Update 'Update the table
.Close 'Close the recordset connection
End With
'update value in the line Subform
Me!SFrmQryLine.Requery
Exit_CmdAddLine_Click:
' de-initialise object variables
Set Rs = Nothing
Set cn = Nothing
Exit Sub
Err_CmdAddLine_Click:
End Sub