I am having troubling making a DLookup to work correctly. A button would be pressed to print the record, before printing it would check if payment details have been entered into another table by looking for the same Case No. I have done the following but it doesn't seem to work. It prints even if a corresponding Case No is not found in 'OurCaseRefNo'. I managed to get it working but realised that when the 'ServicesRec' table had more than one entry with the same Case No (which is possible and OK) it refused to print. So I tried sorting that issue and made a bigger mess. I am quite new to VB code.
Any help highly appreciated.
Code:
Dim stDocName As String
If DLookup("[OurCaseRefNo]", "ServicesRec", "[Case No]=" & "'" & Me![Case No] & "'") > 0 Then
On Error GoTo Err_PrintCaseDetailsReport_Click
stDocName = "CaseDetails"
DoCmd.OpenReport stDocName, acNormal
Exit_PrintCaseDetailsReport_Click:
Exit Sub
Err_PrintCaseDetailsReport_Click:
MsgBox Err.Description
Resume Exit_PrintCaseDetailsReport_Click
Else
MsgBox "Entry of record is incomplete. Please enter payment details."
stDocName = "ServicesRecForm"
stLinkCriteria = "[OurCaseRefNo]=" & "'" & Me![Case No] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If