DLookup Versus SELECT??? (1 Viewer)

CharlesWh

Registered User.
Local time
Today, 01:42
Joined
Jan 19, 2006
Messages
36
I am using some code to retrieve a value to become the value of a text box. Am i right in thinking that when using DLookup NULL values have to be handled whereas by using a SELECT statement I dont have to worry about NULL throwing up an error?

If so, having constructed the following code, how do I direct the value obtained by the SELECT statement, to show up as a value in a text box?

Code:
Dim strSQL As String
Dim ValCustID As Integer

ValCustID = Me.CustID.Value

strSQL = "SELECT TblRadData.CustMacAddress " & _
	"FROM tblRadData " & _
	"WHERE tblRadData.TblcustID='" & ValCustID & "';"
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:42
Joined
Aug 30, 2003
Messages
36,139
You would need to open a recordset on that SQL string and get the value from that. For 1 value, the DLookup is probably simpler, though the recordset is slightly more efficient.
 

CharlesWh

Registered User.
Local time
Today, 01:42
Joined
Jan 19, 2006
Messages
36
Many thanks for your reply and information. As a newbie am just beginning to understand what recordsets are for!
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 18:42
Joined
Aug 30, 2003
Messages
36,139
No problem. I should have added that with a recordset, you'd have to test for it not returning any records (.EOF), similar to how you'd have to handle the Null a DLookup might return. Otherwise you'll get an error trying to set a textbox to a value from the recordset.
 

LPurvis

AWF VIP
Local time
Today, 02:42
Joined
Jun 16, 2008
Messages
1,269
Just to quickly mention that the domain functions aren't always necessarily less efficient. They're the method of choice on local data.
Obviously, recordsets have thousands of other uses, implications and considerations.

But, as with almost everything, it's horses for courses.

Cheers.
 

Users who are viewing this thread

Top Bottom