Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.GoToRecord , , acNewRec does not work

Status
Not open for further replies.

andzejek

MIS
Sep 1, 2007
154
US
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!

Andrew
 
Is your recordset updatable? That is, can you add a new record manually?
 
How are ya andzejek . . .

Sound like the wizard processed the wrong code or your selection in the wizard was wrong. Post the code in the button . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Private Sub cmd_add_new_Click()
On Error GoTo Err_cmd_add_new_Click

DoCmd.GoToRecord , , acNewRec

Exit_cmd_add_new_Click:
Exit Sub

Err_cmd_add_new_Click:
MsgBox Err.Description
Resume Exit_cmd_add_new_Click

End Sub
 
This for is bound to regular table to which I can add records manually
 
What is the value of the AllowAdditions property of the form ?
Does the form contain the primary key ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Allow Additions = yes

No, table does not have the primary key

Andrew
 
Here is what I did:

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)

Can someone help me fix it?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top