guamlet
Board Regular
- Joined
- Dec 29, 2002
- Messages
- 145
I have the following code in place to create a new table entry in the table called "Actions" for each LineID in a list. The rest of the form is copied to the table as the list is iterated. My only problem is that if someone is entering this data in as a "new item" (i.e. they hit the *> button to go to the end of the list), an extra table entry is created that doesn't have any LineID because in order for the iteration to work, I have to use AddNew. Is there a way to either not have this happen or get rid of the extra entry? The code is as follows and is executed when I push a command button on the form:
Private Sub cmdNext_Click()
On Error GoTo Err_cmdNext_Click
Dim db As DAO.Database, rs As DAO.Recordset
Dim strSQL As String, Criteria As String
Dim i As Integer
Set db = CurrentDb
strSQL = "Select * from Actions"
Set rs = db.OpenRecordset(strSQL)
For i = 0 To lstLineID.ListCount - 1
If lstLineID.Selected(i) = True Then
rs.AddNew
'MsgBox (lstLineID.Column(1, i))
rs!LineID = lstLineID.Column(0, i)
' MsgBox (ActionType.Column(1, 1))
rs!ActionType = ActionType.Value '.Column(0, 1)
'MsgBox (EmployeeID.Column(1, 1))
rs!EmployeeID = cmbEmployeeID.Value
'MsgBox (txtPage)
rs!Page = txtPage
rs!Date = dtDate
rs!Notes = txtNotes
' rs!Discontinued = Discontinued.Value
rs.Update
End If
Next i
DoCmd.GoToRecord , , acNext[/code]
Private Sub cmdNext_Click()
On Error GoTo Err_cmdNext_Click
Dim db As DAO.Database, rs As DAO.Recordset
Dim strSQL As String, Criteria As String
Dim i As Integer
Set db = CurrentDb
strSQL = "Select * from Actions"
Set rs = db.OpenRecordset(strSQL)
For i = 0 To lstLineID.ListCount - 1
If lstLineID.Selected(i) = True Then
rs.AddNew
'MsgBox (lstLineID.Column(1, i))
rs!LineID = lstLineID.Column(0, i)
' MsgBox (ActionType.Column(1, 1))
rs!ActionType = ActionType.Value '.Column(0, 1)
'MsgBox (EmployeeID.Column(1, 1))
rs!EmployeeID = cmbEmployeeID.Value
'MsgBox (txtPage)
rs!Page = txtPage
rs!Date = dtDate
rs!Notes = txtNotes
' rs!Discontinued = Discontinued.Value
rs.Update
End If
Next i
DoCmd.GoToRecord , , acNext[/code]