Which method shall I use?

  • Thread starter Thread starter Niklas Östergren
  • Start date Start date
N

Niklas Östergren

Hi!



I have a form which displays a person´s name, address and so on. On this
form I also have a txtbox displaying the person´s membernumber if he/she is
a member. If not I set propertie Visible = False for the textbox and the
lable.



The controlsource for this textbox (txtMemberNo) isn´t in the recordset for
the form. So I need to get this from a query and deside if txtMemberNo shall
be visible or not. Right now I use DCount to see if the person is a member
and if so I use DlookUp to get the membernumber.



Now to my Q:

I have heard that mor or less all D-functions are slow (Dcount, DlookUp and
so on) so my Q is if ther´s a better way to do this than to use DCount and
DLookUp?



The recordset that I get this values from are linked tables (backend).



TIA!

// Niklas
 
Niklas Östergren said:
Hi!



I have a form which displays a person´s name, address and so on. On this
form I also have a txtbox displaying the person´s membernumber if he/she is
a member. If not I set propertie Visible = False for the textbox and the
lable.



The controlsource for this textbox (txtMemberNo) isn´t in the recordset for
the form. So I need to get this from a query and deside if txtMemberNo shall
be visible or not. Right now I use DCount to see if the person is a member
and if so I use DlookUp to get the membernumber.



Now to my Q:

I have heard that mor or less all D-functions are slow (Dcount, DlookUp and
so on) so my Q is if ther´s a better way to do this than to use DCount and
DLookUp?

This is something of a mis-statement. The D-functions instantiate a new
instance of the database object and refresh the collections in that object
when they are called. That amount of overhead makes D-Functions
inefficient to use in queries and loops because you are repetitively
instantiating db objects and refreshing collections. When used on a single
view form to perform a lookup as you're describing a DLookup should be just
fine.

If the field in the WHERE clause of the DLookup is indexed the DLookup
function will be able to take advantage of it and that would make it even
faster.

You could use JUST the DLookup and hide the field when it returns Null and
eliminate the DCount(). That should be an improvement.
 
Niklas said:
I have a form which displays a person´s name, address and so on. On this
form I also have a txtbox displaying the person´s membernumber if he/she is
a member. If not I set propertie Visible = False for the textbox and the
lable.

The controlsource for this textbox (txtMemberNo) isn´t in the recordset for
the form. So I need to get this from a query and deside if txtMemberNo shall
be visible or not. Right now I use DCount to see if the person is a member
and if so I use DlookUp to get the membernumber.

Now to my Q:

I have heard that mor or less all D-functions are slow (Dcount, DlookUp and
so on) so my Q is if ther´s a better way to do this than to use DCount and
DLookUp?


In this case, there's no need to use both DCount and
DLookup. DLookup will return a Null result if it can't find
a matching record. Your code could look like:

Me.txtMemberNo = DLookup("MemberNo", . . .
Me.txtMemberNo.Visible = Not IsNull(Me.txtMemberNo)

A single DLookup is almost as fast as the equivalent
methods, so there's not much to be gained by using a more
complex texhnique. The only thing I can think of that might
have a significant proformance gian is if you Joined the two
tables in the form's record source query so you wouldn't
have to look it up.
 
(snip)
The D-functions instantiate a new instance of the database object
and refresh the collections in that object when they are called.

Just for my interest, has this been proved, or is it just a common belief?
If the former, do you have any references?

Cheers,
TC
 
Well I don´t know what happened again. But I can´t see all of your answers
(using MS Outlook Express) on this computor.

I saw it at home though last night and I´d like to thank you for some
educating answers. I´ll go for only DLookUp and IsNull function instead.
It´s much nicer.

And I´ll use D-functions on several more places where I today have used
Seek, FindFirst since it´s easyer and makes the code more clean.

Thanks a lot guy´s!

// Niklas
 
Back
Top