A
Andrew
Hi all
I need to determine whether a value typed into a text box in a form
exists in a related table, and I'd be interested in the thoughts of
those who know more than me on what is the most efficient way.
2 ways spring to my mind...
-----
Dim rs as ADODB.Recordset
set rs=new ADODB.Recordset
with rs
.ActiveConnection=CurrentProject.Connection
.Source="SELECT * from tblRelatedTable where strCode='" & txtCode &
"'"
.Open
If .EOF then _
'We know that there are no related records, handle it.
.Close
end with
Set rs=nothing
----
dim varMatch as variant
varMatch=dlookup("strCode","tblRelatedTable","strCode='" & txtCode &
"'")
if isnull(varMatch) then _
'We know that there are no related records, hadle it
---
Logic would suggest that the second of these ways would be quicker,
but somehow I instinctively want to go the first way.... probably just
my predilection for using 20 lines of code where 1 would do. But can
anyone give me a definitive answer on this? Or is there another way
which would be better yet?
Many thanks
Andrew
I need to determine whether a value typed into a text box in a form
exists in a related table, and I'd be interested in the thoughts of
those who know more than me on what is the most efficient way.
2 ways spring to my mind...
-----
Dim rs as ADODB.Recordset
set rs=new ADODB.Recordset
with rs
.ActiveConnection=CurrentProject.Connection
.Source="SELECT * from tblRelatedTable where strCode='" & txtCode &
"'"
.Open
If .EOF then _
'We know that there are no related records, handle it.
.Close
end with
Set rs=nothing
----
dim varMatch as variant
varMatch=dlookup("strCode","tblRelatedTable","strCode='" & txtCode &
"'")
if isnull(varMatch) then _
'We know that there are no related records, hadle it
---
Logic would suggest that the second of these ways would be quicker,
but somehow I instinctively want to go the first way.... probably just
my predilection for using 20 lines of code where 1 would do. But can
anyone give me a definitive answer on this? Or is there another way
which would be better yet?
Many thanks
Andrew