Dlookup question

G

Guest

can you use dlookup to find more than 1 item from a table e.g.,
dlookup("Field1","field2",[tblName],field 1=0)
 
D

Douglas J. Steele

Sort of.

DLookup will only return a single value, but you can have it concatenate
fields together. For example, you could have it return field1 and field2
separated by a comma, and then split the values apart afterwards.

Dim strField1 As String
Dim strField2 As String
Dim strReturn As String

strReturn = DLookup("[Field1] & ',' & [Field2]", _
"[tblName]", "[Field1] = 0")

strField1 = Left(strReturn, InStr(strReturn, ",") - 1)
strField2 = Mid(strReturn, InStr(strReturn, ",") + 1)
 
G

Guest

Amaizing, I had no Idea.
So you can actually return unlimited amount of fields

Dim strField1 As String
Dim strField2 As String
Dim strField3 As String
Dim strReturn As String

strReturn = DLookup("[Field1] & ',' & [Field2] & ',' & [Field3]", _
"[tblName]", "[Field1] = 0")

strField1 = split(strReturn ,",")(0)
strField2 = split(strReturn ,",")(1)
strField3 = split(strReturn ,",")(2)

Thank you, Douglas

Douglas J. Steele said:
Sort of.

DLookup will only return a single value, but you can have it concatenate
fields together. For example, you could have it return field1 and field2
separated by a comma, and then split the values apart afterwards.

Dim strField1 As String
Dim strField2 As String
Dim strReturn As String

strReturn = DLookup("[Field1] & ',' & [Field2]", _
"[tblName]", "[Field1] = 0")

strField1 = Left(strReturn, InStr(strReturn, ",") - 1)
strField2 = Mid(strReturn, InStr(strReturn, ",") + 1)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



JOM said:
can you use dlookup to find more than 1 item from a table e.g.,
dlookup("Field1","field2",[tblName],field 1=0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top