command button conflict

S

Stephen D Cook

My history button is causing my add record button to select first
found record and not add a new record.

I have a form with 3 text boxes, 2 command buttons, and a subform.
The form is tied to a table. The 2 command buttons are an Add record
button, and a show history button.
The serial number textbox is tied to the serial number field in the
table.

The subform was created by dragging a query to the main form.
The query has serialNumber, type, and problem for the fields.

The serialNumber field of the query has
[Forms]![frmAddShowRecord]![txtSN] for the criteria.

The code for the form is as follows:

Private Sub Form_Activate()
DoCmd.Maximize
DoCmd.GoToRecord , , acNewRec
txtSN.SetFocus
End Sub

Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click
If Len(Me.txtSN & vbNullString) = 0 Then
MsgBox ("you must enter a value in the serial number field
first")
GoTo Err_cmdAdd_Click
End If

txtDate = Format(Now, "MM/DD/YYYY")
Me.txtSN.Requery

DoCmd.GoToRecord , , acNewRec
If Not Me.NewRecord Then
RunCommand acCmdRecordsGoToNew
End If
Me.txtSN.SetFocus

Exit_cmdAdd_Click:
Exit Sub

Err_cmdAdd_Click:
'MsgBox Err.Description
Resume Exit_cmdAdd_Click

End Sub

Private Sub cmdHistory_Click()
On Error GoTo Err_cmdHistory_Click
DoCmd.ApplyFilter , "[SerialNumber] =
Forms!frmAddShowRecord!txtSN"
'Me.txtSN.Requery
Exit_cmdHistory_Click:
Exit Sub

Err_cmdHistory_Click:
MsgBox Err.Description
Resume Exit_cmdHistory_Click

End Sub


The form works fine by inserting a new record if you click the Add
button.
The form works fine for showing the history of the serial Number.

But, when you click the History button first, then click the Add
button, the first occurance of the serial number in the table is
modified to the new data.

How do I get the Add button to work correctly after clicking the
History button?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top