Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to handle multiple query results in Access 2000 1

Status
Not open for further replies.

vamoose

Programmer
Oct 16, 2005
320
MX
I am using the following query to return one result and assign it to a variable in Access 2000:

SQLa = "Select Actual from SameAs where SA1 = '" & Coil & "';"
Set rs = conn.Execute(SQLa, , adCmdText)
SA1 = rs.Fields("Actual").Value

My question is how to handle the results being assigned to a variable if more that 1 result is returned.
Thank you for the assistance.
 
Hi...

If you only want one item returned, why is there a possibity of multiple items for your criteria?

With your current SQL you could try " Select TOP 1....

or

Your could use DLookup and return the first instance...
 
My question is how to handle the results being assigned to a variable if more that 1 result is returned.
That entirely depends on what you want to do with the data. You can choose to completely ignore the other records, if you want (you realize that SA1 is only getting assigned the "Actual" value of the current record?).

 
I would like all instaces returned and there is the possibility that there could be more than 1 result
 
If there are more than 1 resulting records then I need to assign it to a variable. Thank you.
 
Make the variable an array and use the GetRows method of the recordset to copy it's values to the array.

 



Code:
dim fld as field, nRow as long
SQLa = "Select Actual from SameAs where SA1 = '" & Coil & "';"
Set rs = conn.Execute(SQLa, , adCmdText)
nRow = 1
do 
for each fld in rs.fields
   msgbox fld.name & " equals " & fld.value & " in row " & nrow
next
rs.movenext
nrow = nrow + 1
loop until rs.eof


Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top