Help setting label boxes with values from MySql database

Hi,
    I have the following code:

    cnn1.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=;" & _
                          "DATABASE=;USER=;PASSWORD=;OPTION=3;"
    cnn1.Open
 

     SQL1 = "SELECT content_url FROM content WHERE content_category_id ='1'"
     rs1.Open SQL1, cnn1, adOpenForwardOnly, adLockOptimistic

   Set cnn1 = Nothing

Which makes a DB connection, however I also have 5 label boxes on a form and what I wish to do is scan the content_url table and display each promotion which is searchable via the content_category_id=1 and display each in their own label box, how can this be completed?

Thanks
damianb123Asked:
Who is Participating?
 
DhaestCommented:
You can change the caption of the labels.

If you don't have an array, you'll need to do something like this...

num = 0
Do While Not rs.EOF
   if num=0 then label1.caption = rs!content_url end if
   if num=1 then label2.caption = rs!content_url end if
   if num=2 then label3.caption = rs!content_url end if
   if num=3 then label4.caption = rs!content_url end if
   if num=4 then label5.caption = rs!content_url end if
    num = num + 1
     rs.MoveNext
Loop
0
 
DhaestCommented:
Loop over your recordset
In example below I assume that you created an array of your textboxes (all with the same name, but another index)

num = 0
Do While Not rs.EOF
    textbox(i).Text = rs!content_url
    num = num + 1
     rs.MoveNext
Loop
0
 
damianb123Author Commented:
They are label boxes, so they cannot be changed, but I didn't configure as an array, should I change to textboxes and set as an array?

Thx
0
 
damianb123Author Commented:
I changed my label boxes to an array in the end called Voucher and used this:

num = 0
Do While Not rs1.EOF
    Voucher(i).Caption = rs1!content_url
    num = num + 1
     rs1.MoveNext
Loop

Which does work, but ONLY populates the first label box out of the five listed.  There are three items in my database, which should be showing on the first 3 label boxes....

What have I done wrong????

Thx
0
 
damianb123Author Commented:
This worked a treat, thanks v much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.