two variable dlookup string

B

Brenton Anderson

how would i structure the string in a do lookup function
to lookup part numbers under a po/order#, whereby part
number is multiple lines?

POnumber, OrderNo, Partnumber
1234 7890 abc
1234 7890 def
1234 7890 ghi
5678 4567 abc
5678 4567 def


brenton
 
J

John Vinson

how would i structure the string in a do lookup function
to lookup part numbers under a po/order#, whereby part
number is multiple lines?

POnumber, OrderNo, Partnumber
1234 7890 abc
1234 7890 def
1234 7890 ghi
5678 4567 abc
5678 4567 def

What do you want to look up? All lines for Partnumber abc? DLookUp
looks up one single value - if that's ok, which PONumber do you want?

Please explain the context and what you're expecting to get as a
result.
 
M

Microsoft News Groups

Brenton,

As has been noted you can't look up more than one record with DLookup().

You can write your own routine though. The code below assumes you are using
DAO.

Function GetPartNumber(lngPONumber As Long, lngOrderNo As Long) As String
Dim rs As Recordset
Dim strPartNumber As String
Dim strSQL As String

strSQL = "SELECT PartNumber FROM PartNumberTable WHERE OrderNo=" &
lngOrderNo & " AND PONumber=" & lngPONumber ' this should be a single
line
Set rs = CurrentDb.OpenRecordset(strSQL,dbOpenForwardOnly,dbReadOnly)
Do While Not rs.EOF
strPartNumber = strPartNumber & rs!PartNumber
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
GetPartNumber = strPartNumber
End Function
 

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