Code Opens form when there is no Data ? See Code Below. Thanks, Dave

  • Thread starter Thread starter Dave Elliott
  • Start date Start date
D

Dave Elliott

This code works , except that it still opens the FPayments form even when
there is no matching record, Why ???



Dim stDocName As String
Dim stLinkCriteria As String
Dim VarX As Variant

stDocName = "FPayments"
stLinkCriteria = "[Order ID]=" & Me![Order ID]
'VarX = DLookup("' & [Order ID] & '", "Orders", "[Order ID] Like
Forms![Edit Quote]![Order ID]")
VarX = DLookup("' & [Order ID] & '", "Orders", "[Order ID] =
Forms![Edit Quote]![Order ID]")

If IsNull(VarX) Then
MsgBox "No Payments Have Been Made"
Else: DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name
End If
 
How about using exactly the same phrase for the Critieria of the DLookup()
as you do for the WhereCondition of the OpenReport:

Dim stDocName As String
Dim stLinkCriteria As String
Dim VarX As Variant

stDocName = "FPayments"
stLinkCriteria = "[Order ID] = " & Me![Order ID]
VarX = DLookup("Order ID", "Orders", stLinkCriteria)

If IsNull(VarX) Then
MsgBox "No Payments Have Been Made"
Else
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name
End If

It may be more efficient to cancel the NoData event of the report, and trap
error 2501 in this code.
 
Back
Top