I have a form with two fields, street number and street name. If the combination of the two does not exist on a current record I want to open the form with these values already set on the form. Here is the code I have, but get error on highlighted row. The Contacts form is used for adding and editing of records.
Please advise the best method of doing this.
Code:
strnum = Me![strnum]
strname = Me![strname]
intcount = DCount("ID", "[Contacts]", "Address = '" & strname & "' and street_no = '" & strnum & "'")
Dim stdocname As String
stdocname = "Contacts"
If intcount > 0 Then
Dim strLinkCriteria As String
strLinkCriteria = "[Address] =" & "'" & Me![strname] & "'" & " And [street_no]=" & "'" & Me![strnum] & "'"
DoCmd.Close
DoCmd.OpenForm stdocname, , , strLinkCriteria
Else
[B][COLOR="Red"] Me.strname = Forms![Contacts]![Address][/COLOR][/B]
Me.strnum = Forms![Contacts]![street_no]
DoCmd.Close
DoCmd.OpenForm stdocname
DoCmd.GoToRecord , , acNewRec
End If
Please advise the best method of doing this.