T
Tony Williams
I have created a simple find form. It has one control which is a combo box
based on a field (txtsurname) in my table (tblcontacts). I have a command
button that when the user has selected the surname of the record they want
to find opens up a form (frmcontacts). However when the form opens to show
the records it also adds a new record with the same name. Why is this
happening?
The code behind the OnClick event of the command button is
Private Sub Command2_Click()
On Error GoTo Command2_Click_Err
Dim stLinkCriteria As String
stLinkCriteria = "[txtsurname]=" & "'" & Me![txtSurname] & "'"
If IsNull(DLookup("[txtsurname]", "tblContacts", stLinkCriteria)) Then
MsgBox "There is no Contact with this Surname.", _
vbInformation, "No Matching Record"
Else
DoCmd.OpenForm "frmContacts", , , "[txtSurname]=" & "'" &
Me![txtSurname] & "'"
End If
Command2_Click_Exit:
Exit Sub
Command2_Click_Err:
Response = acDataErrContinue
Resume Command2_Click_Exit
End Sub
Thank you
Tony
based on a field (txtsurname) in my table (tblcontacts). I have a command
button that when the user has selected the surname of the record they want
to find opens up a form (frmcontacts). However when the form opens to show
the records it also adds a new record with the same name. Why is this
happening?
The code behind the OnClick event of the command button is
Private Sub Command2_Click()
On Error GoTo Command2_Click_Err
Dim stLinkCriteria As String
stLinkCriteria = "[txtsurname]=" & "'" & Me![txtSurname] & "'"
If IsNull(DLookup("[txtsurname]", "tblContacts", stLinkCriteria)) Then
MsgBox "There is no Contact with this Surname.", _
vbInformation, "No Matching Record"
Else
DoCmd.OpenForm "frmContacts", , , "[txtSurname]=" & "'" &
Me![txtSurname] & "'"
End If
Command2_Click_Exit:
Exit Sub
Command2_Click_Err:
Response = acDataErrContinue
Resume Command2_Click_Exit
End Sub
Thank you
Tony