To avoid getting an error when passing a variable to a form, using If Not against the EOF (I believe means End of File) property.
If Not Me.Recordset.EOF And Not Me.Recordset.EOF Then Dim stDocName As String Dim stLinkCriteria As String stDocName = "someform" stLinkCriteria = "[recordnumber]=" & Me.[recordnumber] DoCmd.OpenForm stDocName, , , stLinkCriteria Else MsgBox "No Record Selected!" End If