DLookUp Trouble

D

DS

This DLoopUp doesn't seem to be working.....

I'm looking up the Taxed field. If No records where Taxed equals "True"
are found I want the loop to run...If no nothing happens.

Private Sub Command78_Click()
With Forms!Sales.SalesDetails.Form.Recordset
If DLookup("[Taxed]", "SalesDetailsQ", "[SalesID]=" &
Forms!Sales!SalesID & " AND [Taxed]=True") = 0 Then
.MoveFirst
Do While .EOF = False And .BOF = False
.Edit
!SDInclusive = True
!SDTaxed = False
.Update
.MoveNext
Loop
End If
End With
End Sub

Thanks
DS
 
N

Nikos Yannacopoulos

A Dlookup that failed to find a matching record will return Null, not a
zero.
Your condition DLookup(yada yada) = 0 will never be satisfied, because
if [Taxed]=True and a record is found then Taxed returned by the DLookup
equals True, which equals -1 in a mathematical expression! On the other
hand, records with Taxed = False, which equals 0 in a mathematical
expression, do not satisfy the [Taxed]=True part of the where clause.
In a nutshell, what you need to do is change your If expression to:

If IsNull(DLookup("[Taxed]", "SalesDetailsQ", "[SalesID]=" _
& Forms!Sales!SalesID & " AND [Taxed]=True")) Then

HTH,
Nikos
 
D

DS

Nikos said:
A Dlookup that failed to find a matching record will return Null, not a
zero.
Your condition DLookup(yada yada) = 0 will never be satisfied, because
if [Taxed]=True and a record is found then Taxed returned by the DLookup
equals True, which equals -1 in a mathematical expression! On the other
hand, records with Taxed = False, which equals 0 in a mathematical
expression, do not satisfy the [Taxed]=True part of the where clause.
In a nutshell, what you need to do is change your If expression to:

If IsNull(DLookup("[Taxed]", "SalesDetailsQ", "[SalesID]=" _
& Forms!Sales!SalesID & " AND [Taxed]=True")) Then

HTH,
Nikos
This DLoopUp doesn't seem to be working.....

I'm looking up the Taxed field. If No records where Taxed equals
"True" are found I want the loop to run...If no nothing happens.

Private Sub Command78_Click()
With Forms!Sales.SalesDetails.Form.Recordset
If DLookup("[Taxed]", "SalesDetailsQ", "[SalesID]=" &
Forms!Sales!SalesID & " AND [Taxed]=True") = 0 Then
.MoveFirst
Do While .EOF = False And .BOF = False
.Edit
!SDInclusive = True
!SDTaxed = False
.Update
.MoveNext
Loop
End If
End With
End Sub

Thanks
DS
Great answer! And it worked also! Many thanks
DS
 
N

Nikos Yannacopoulos

Welcome.
Nikos said:
A Dlookup that failed to find a matching record will return Null, not
a zero.
Your condition DLookup(yada yada) = 0 will never be satisfied, because
if [Taxed]=True and a record is found then Taxed returned by the
DLookup equals True, which equals -1 in a mathematical expression! On
the other hand, records with Taxed = False, which equals 0 in a
mathematical expression, do not satisfy the [Taxed]=True part of the
where clause.
In a nutshell, what you need to do is change your If expression to:

If IsNull(DLookup("[Taxed]", "SalesDetailsQ", "[SalesID]=" _
& Forms!Sales!SalesID & " AND [Taxed]=True")) Then

HTH,
Nikos
This DLoopUp doesn't seem to be working.....

I'm looking up the Taxed field. If No records where Taxed equals
"True" are found I want the loop to run...If no nothing happens.

Private Sub Command78_Click()
With Forms!Sales.SalesDetails.Form.Recordset
If DLookup("[Taxed]", "SalesDetailsQ", "[SalesID]=" &
Forms!Sales!SalesID & " AND [Taxed]=True") = 0 Then
.MoveFirst
Do While .EOF = False And .BOF = False
.Edit
!SDInclusive = True
!SDTaxed = False
.Update
.MoveNext
Loop
End If
End With
End Sub

Thanks
DS

Great answer! And it worked also! Many thanks
DS
 

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

Similar Threads

Code Help 10
Nested IF 7
DSum Problem 2
ECHO in the right place? 0
DSUM Not Working 5
Looping Code Question 0
Flickering Fields 1
DLookUp Problem 7

Top