Create a new record only if phone number isn't found?

Code:
varRP = Me.RPphone

strSQL1 = [COLOR="red"]"SELECT [RPcontactnumber], [RPid]" & _
" FROM ReportingParties" & _
" WHERE [RPcontactnumber] ='" & varRP & "' ;"[/COLOR]
Set db = CurrentDb()

Set LRS = db.OpenRecordset(strSQL1)

If LRS.EOF = False Then
[COLOR="Red"]Me.RPid = DLookup("[RPid]", "ReportingParties", "RPcontactnumber = '" & Me.RPphone & "'")[/COLOR]
Else
DoCmd.OpenForm ("ReportingPartiesForm")
End If

LRS.Close

Set LRS = Nothing

The two highlighted strings are exactly the same.
Why are you doing a lookup on a table that you already have the recrodset set to?

Change the second string to
Code:
Me.RPid = LRS("RPid")
 

Users who are viewing this thread

Back
Top Bottom