I have a form with textboxes and listbox which are showing fields of the table(few fields and few records - listbox) and using a wizard I created "Add New" record button and it does not work! It goes to the last record but is is not adding new one!
Private Sub cmd_add_Click()
On Error GoTo Err_cmd_add_Click
Dim strCtrlName As String
Dim i As Integer
Dim ctl As Control
i = 0
If UCase(Me.cmd_add.Caption) = "ADD" Then
Me.cmd_add.Caption = "Save"
For Each ctl In Me.Controls
With ctl
Select Case .ControlType
Case acLabel
Case acTextBox
If i < 13 Then
strCtrlName = ctl.Name
Me(strCtrlName).Value = " "
Me(strCtrlName).Locked = False
i = i + 1
End If
End Select
End With
Next ctl
Me.Vendor_ID.SetFocus
Else
Me.cmd_add.Caption = "Add"
rs.AddNew
For Each ctl In Me.Controls
With ctl
Select Case .ControlType
'Case acLabel
Case acTextBox
If i < 13 Then
strCtrlName = rs.Fields(i).Name
rs.Fields(i).Value = Me(strCtrlName).Value
i = i + 1
End If
End Select
End With
Next ctl
rs.Update
End If
Me.Requery
Exit_cmd_add_Click:
Exit Sub
Err_cmd_add_Click:
MsgBox Err.Description
Resume Exit_cmd_add_Click
End Sub
but now it is adding one record and editing other one so after adding record I have two identical records in the table(just one more record)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.