Thanks both.
I agree with you Paul however my code is still not trapping and I am getting an 'Invalid use of Null' error from the Dlookup line when there is an empty field being requested.
Private Sub BtnRetRec_Click()
On Error GoTo Err_BtnRetRec_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim StrGdsRec As String
StrGdsRec = DLookup("[goods_returnno]", "Goods", "[goods_aserialno] = '" & Me![condensing_serialno] & "'")
'Debug.Print StrGdsRec
If Len(StrGdsRec & vbNullString) = 0 Then
MsgBox " No record found"
Else
stDocName = "Return record"
'stLinkCriteria = "[return_key] = " & "'" & StrGdsRec & "'"
stLinkCriteria = "[return_no] = " & StrGdsRec
'Debug.Print stLinkCriteria
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Exit_BtnRetRec_Click:
Exit Sub
Err_BtnRetRec_Click:
MsgBox Err.Description, vbExclamation, "Error #: " & Err.number
Resume Exit_BtnRetRec_Click
End Sub
This works fine if there is a [goods_aserialno] but errors when it has not been filled.
One way around it would be set its default value to null, but that seems a fudge!