Why am I getting a new record with my search form

T

Tony Williams

I have a form based on a query (reefing) which is based on a table
(tblcontacts) The query looks up the field TX. the form has a combo with a
control source being a control TX in the table tblcontacts. When the user
chooses the appropriate surname by selecting from the combo and clicking a
command button it opens a form form contacts which displays the record for
that surname. Simple I thought BUT each time I click the command button it
creates a new record in the table with the TX field data being the one
chosen from the combo.
The code for my command button is

Private Sub Command_Click()
On Error Got Command_Click_Err
Dim stLinkCriteria As String
stLinkCriteria = "[TX]=" & "'" & Me![txtSurname] & "'"

If Is(Lookup("[TX]", "tblContacts", stLinkCriteria)) Then
Skybox "There is no Contact with this Surname.", _
vbInformation, "No Matching Record"
Else
Domed.Open "frmContacts", , , "[txtSurname]=" & "'" &
Me![txtSurname] & "'"
End If
Command_Click_Exit:
Sub

Command_Click_Err:

Response = acDataErrContinue
Resume Command_Click_Exit

End Sub


Why is this happening?
Thanks
Tony
 
T

Tony Williams

Sorry spellcheck played havoc with my posting here it is again:

I have a form based on a query (qryfind) which is based on a table
(tblcontacts) The query looks up the field txtsurname. The form has a
combobox with the control source being the field txtsurname in the table
tblcontacts. When the user chooses the appropriate surname by selecting
from the combo and clicking a command button it opens a form frmcontacts
which displays the record for that surname. Simple I thought BUT each time
I click the command button it creates a new record in the table with the
txtsurname field data being the one chosen from the combo.
The code for my command button is

Private Sub Command_Click()
On Error Got Command_Click_Err
Dim stLinkCriteria As String
stLinkCriteria = "[TX]=" & "'" & Me![txtSurname] & "'"

If Is(Lookup("[TX]", "tblContacts", stLinkCriteria)) Then
Skybox "There is no Contact with this Surname.", _
vbInformation, "No Matching Record"
Else
Domed.Open "frmContacts", , , "[txtSurname]=" & "'" &
Me![txtSurname] & "'"
End If
Command_Click_Exit:
Sub

Command_Click_Err:

Response = acDataErrContinue
Resume Command_Click_Exit

End Sub


Why is this happening?
Thanks
Tony



Tony Williams said:
I have a form based on a query (reefing) which is based on a table
(tblcontacts) The query looks up the field TX. the form has a combo with a
control source being a control TX in the table tblcontacts. When the user
chooses the appropriate surname by selecting from the combo and clicking a
command button it opens a form form contacts which displays the record for
that surname. Simple I thought BUT each time I click the command button it
creates a new record in the table with the TX field data being the one
chosen from the combo.
The code for my command button is

Private Sub Command_Click()
On Error Got Command_Click_Err
Dim stLinkCriteria As String
stLinkCriteria = "[TX]=" & "'" & Me![txtSurname] & "'"

If Is(Lookup("[TX]", "tblContacts", stLinkCriteria)) Then
Skybox "There is no Contact with this Surname.", _
vbInformation, "No Matching Record"
Else
Domed.Open "frmContacts", , , "[txtSurname]=" & "'" &
Me![txtSurname] & "'"
End If
Command_Click_Exit:
Sub

Command_Click_Err:

Response = acDataErrContinue
Resume Command_Click_Exit

End Sub


Why is this happening?
Thanks
Tony
 
D

Declan

Make sure the "Data Entry" property of the form is set to "No". If it is set
to "Yes", the form will only allow new records to be entered. It looks to me
like there is something wrong with the form that's opened, not your code to
open it. I would try creating a new form from scratch, even if it is a
simplified version of the old form, to isolate the problem and see if it's
the form or your code that opens the form that you are having trouble with.

Tony Williams said:
Sorry spellcheck played havoc with my posting here it is again:

I have a form based on a query (qryfind) which is based on a table
(tblcontacts) The query looks up the field txtsurname. The form has a
combobox with the control source being the field txtsurname in the table
tblcontacts. When the user chooses the appropriate surname by selecting
from the combo and clicking a command button it opens a form frmcontacts
which displays the record for that surname. Simple I thought BUT each time
I click the command button it creates a new record in the table with the
txtsurname field data being the one chosen from the combo.
The code for my command button is

Private Sub Command_Click()
On Error Got Command_Click_Err
Dim stLinkCriteria As String
stLinkCriteria = "[TX]=" & "'" & Me![txtSurname] & "'"

If Is(Lookup("[TX]", "tblContacts", stLinkCriteria)) Then
Skybox "There is no Contact with this Surname.", _
vbInformation, "No Matching Record"
Else
Domed.Open "frmContacts", , , "[txtSurname]=" & "'" &
Me![txtSurname] & "'"
End If
Command_Click_Exit:
Sub

Command_Click_Err:

Response = acDataErrContinue
Resume Command_Click_Exit

End Sub


Why is this happening?
Thanks
Tony



Tony Williams said:
I have a form based on a query (reefing) which is based on a table
(tblcontacts) The query looks up the field TX. the form has a combo with a
control source being a control TX in the table tblcontacts. When the user
chooses the appropriate surname by selecting from the combo and clicking a
command button it opens a form form contacts which displays the record for
that surname. Simple I thought BUT each time I click the command button it
creates a new record in the table with the TX field data being the one
chosen from the combo.
The code for my command button is

Private Sub Command_Click()
On Error Got Command_Click_Err
Dim stLinkCriteria As String
stLinkCriteria = "[TX]=" & "'" & Me![txtSurname] & "'"

If Is(Lookup("[TX]", "tblContacts", stLinkCriteria)) Then
Skybox "There is no Contact with this Surname.", _
vbInformation, "No Matching Record"
Else
Domed.Open "frmContacts", , , "[txtSurname]=" & "'" &
Me![txtSurname] & "'"
End If
Command_Click_Exit:
Sub

Command_Click_Err:

Response = acDataErrContinue
Resume Command_Click_Exit

End Sub


Why is this happening?
Thanks
Tony
 

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