Sub YourSub
If ExistsInTable2(FieldInTable1) Then
[COLOR="Green"] 'do this[/COLOR]
Else
[COLOR="Green"] 'do that[/COLOR]
End If
End Sub
Private Function ExistsInTable2(someValue as ???) As Boolean
ExistsInTable2 = DCount("*", "Table2", "SomeField = " & someValue) > 0
End Function
Private Function FieldInTable1 As ???
[COLOR="Green"] 'not sure how you calculate this, probably you need to find a single row first[/COLOR]
End Function
Whichever method you choose, DLookup or DCount, handle the dates, numbers and strings properly as explained here:
http://allenbrowne.com/casu-07.html
State = DLookup("supplierstate", "suppliers", "supplierid = " & Me.[COLOR="Blue"]SubformControlName[/COLOR].vendorid)
Sure, give it a go! It's similar to writing the WHERE clause in SQL.
I like Dlookup - except when the record I want isn't the first record that matches. Dlookup's big fault is that it only returns the first record. And vbaInet's mention of Nz() for Nulls is a big blessing!
DLookup("Field", "Table/Query", "ID = " & Me.txtID & " AND DateOfBirth = #" & Me.txtDOB & "#")
I'm unclear. Why would it be slow to 'chain' to another Table BY KEYS?? Is there another way, more efficient, to get a record from another table ?Actually a DLookup() is absolutely fine, it's just slow that's it.