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

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
 
A

Allen Browne

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top