I'm trying to use Dlookup to grab thes value in a field from a query. It works if I copy the values to a table however I want to avoid this if possible. Here's the code below
Private Sub Form_Load()
Dim MyDate, MyDay, MyYear, ent1, ent2, ent3, ent4, ent5
DoCmd.OpenQuery "qryCalcDifference"
DoCmd.GoToRecord , , acLast
ent1 = DLookup("Ent1", "qryCalcDifference")
ent2 = DLookup("Ent2", "qryCalcDifference")
ent3 = DLookup("Ent3", "qryCalcDifference")
ent4 = DLookup("Ent4", "qryCalcDifference")
ent5 = DLookup("Ent5", "qryCalcDifference")
If ent1 > 1.15 Or ent1 < 0.85 Or ent2 > 1.15 Or ent2 < 0.85 Or ent3 > 1.15 Or ent3 < 0.85 Or ent4 > 1.15 Or ent4 < 0.85 Or ent5 > 1.15 Or ent5 < 0.85 Then
MsgBox "PCS Diagnostics has detected there may be an error in the PCS system. Please contact Pedestrian Counting Systems.", vbExclamation, "PCS Error Detection"
End If
End Sub
Can Dlookup not be used in queries or have I got code wrong somewhere?
Private Sub Form_Load()
Dim MyDate, MyDay, MyYear, ent1, ent2, ent3, ent4, ent5
DoCmd.OpenQuery "qryCalcDifference"
DoCmd.GoToRecord , , acLast
ent1 = DLookup("Ent1", "qryCalcDifference")
ent2 = DLookup("Ent2", "qryCalcDifference")
ent3 = DLookup("Ent3", "qryCalcDifference")
ent4 = DLookup("Ent4", "qryCalcDifference")
ent5 = DLookup("Ent5", "qryCalcDifference")
If ent1 > 1.15 Or ent1 < 0.85 Or ent2 > 1.15 Or ent2 < 0.85 Or ent3 > 1.15 Or ent3 < 0.85 Or ent4 > 1.15 Or ent4 < 0.85 Or ent5 > 1.15 Or ent5 < 0.85 Then
MsgBox "PCS Diagnostics has detected there may be an error in the PCS system. Please contact Pedestrian Counting Systems.", vbExclamation, "PCS Error Detection"
End If
End Sub
Can Dlookup not be used in queries or have I got code wrong somewhere?