?
Solved

Dynamic Picture box, button...

Posted on 2000-05-03
3
Medium Priority
?
186 Views
Last Modified: 2010-05-02
Hi Experts,

  Can I check with you whether I can display picture boxes, buttons, label dynamically, that means I display them according to the number of records in my database.
is it possible ?
if yes, can show me some simple code on how to ?

Thanks
0
Comment
Question by:seahpc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 300 total points
ID: 2772967
The simplest method of this is to add one of each control to your form, set the index property to 0, (zero, not blank). You can then load additional elements of the control array using the load statement.

Here is an example:

rstData.MoveFirst
For intCount = 1 To rstData.RecordCount - 1
  Load txtText(intCount)
  txtText(intCount).Left = 100
  txtText(intCount).Top = 100 + 200 * intCount
  txtText(intCount).Text = rstData!TextField
  txtText(intCount).Visible = True
  Load lblLabel(intCount)
  lblLabel(intCount).Left = 2500
  lblLabel(intCount).Top = 100 + 200 * intCount
  lblLabel(intCount).Caption = rstData!LabelField
  lblLabel(intCount).Visible = True
  rstData.MoveNext
Next

To Clear Down:

rstData.MoveFirst
For intCount = 1 To rstData.RecordCount - 1
  Unload txtText(intCount)
  Unload lblLabel(intCount)
  rstData.MoveNext
Next
0
 
LVL 9

Expert Comment

by:Dalin
ID: 2772993
Surely you can.
Using controlArray.

After you open your recordset (say you call it MyRS), check how many record you have. Then use Load to add more picturebox, label and buttons.
At design time, you put one of each in your form. say you call it MyPic, MyBut, and MyLab. set the Index property to 0.

add the code to create the array
With MyRS
If .EOF = False then
     .MoveLast
     .MoveFirst
     MyLab(0).Caption = !somefieldName
     MyBut(0).caption = !SomeFieldName
     MyPic(0).Picture = Whatever
     If .RecordCount > 1 then
             For i   = 1 to .RecordCount -1
                   .MoveNext
                   Load MyLab(i)
                   Load MyBut(i)
                   Load MyPic(i)
                    MyLab(i).Caption = !somefieldName
                     MyBut(i).caption = !SomeFieldName
                    MyPic(i).Picture = Whatever
                  'set the position in the form
                   MyLab(i).Left = whatever
                   MyLab(i).Top = whatever
                  ...
               Next i
         End If
End With






0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2774141
an alternative to creating a control array:

http://support.microsoft.com/support/kb/articles/Q190/6/70.ASP?LNG=CAN&SA=&FR=0

it also allows you to add controls that arent on your form to begin with

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question