AddNew problem

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]
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Set the AllowAdditions property of the form to False. This will disable the "New Record " navigation button on your form. Then, at the beginning of the code behind your button (the code above), put a line like

Code:
Me.AllowAdditions = True

and at the end,

Code:
Me.AllowAdditions = False


HTH,

Russell
 
Upvote 0

Forum statistics

Threads
1,221,522
Messages
6,160,308
Members
451,637
Latest member
hvp2262

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top