0

I was wondering if someone could help me.

I have an array which is like this

fileArray = '2612(25).jpg', '2012(15).jpg', '2012(31).jpg', '2012(21).jpg', '2012(58).jpg'

Now i have the following code.

Set DBConn = CreateObject("ADODB.Connection")
DBConn.Open strOLEDBString, strODBCUser, strODBCPass

SQL = "SELECT p, sum(vote) as likes FROM vote WHERE p in (" & fileArray & ") GROUP BY p ORDER BY sum(vote) desc"

Set rs = DBConn.Execute(SQL)

If rs.eof Then
    HTMLTable = HTMLTable & " Nothing returned"
Else 
    HTMLTable = HTMLTable & rs("p")
End If

The results only show the last filename in the array, it should be displaying all of them.

8
  • I think you have an error here. How can you take an array of a bunch of different strings and jam it into a space where only one string is expected? Commented Jun 13, 2013 at 3:00
  • Are u familiar with SQL IN statement? Commented Jun 13, 2013 at 3:02
  • @YuriyGalanter No im not Commented Jun 13, 2013 at 3:05
  • @YuriyGalanter-who are you asking? If me, then, yes, I'm familiar with it. Commented Jun 13, 2013 at 3:05
  • 1
    @STLDeveloper Actually I beleive in this case it's a single string of comma separated values. Commented Jun 13, 2013 at 3:16

2 Answers 2

1

You need to loop thru ADO Recordset to get all the records:

...
Else
  Do While Not rs.eof
    HTMLTable = HTMLTable & "<tr><td>" & rs("p") & "</td></tr>"
    rs.MoveNext
  Loop
End If
Sign up to request clarification or add additional context in comments.

4 Comments

Where do you assign initial value of HTMLTable? It should have at least the same result you did before, but possibly more. Depending on result returned by the query. How many records do u get if u run the query directly in DB?
Quite a few lines up, using HTMLTable = "<table border = 0 width=""100%"" >" & vbCRLF
I've modified my code taking into account this being a table, can u give it a try?
Opps ... My bad ... I forgot to add the 'Not' in the Do While statement doiiiiii .. That works perfect now ... Thank you :)
0

You need "" around your filearray statement.

fileArray = "'2612(25).jpg', '2012(15).jpg', '2012(31).jpg', '2012(21).jpg', '2012(58).jpg'"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.