Link to home
Start Free TrialLog in
Avatar of damianb123
damianb123Flag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

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
Avatar of damianb123

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
This worked a treat, thanks v much!