Solved

Dynamic Picture box, button...

Posted on 2000-05-03
3
184 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 100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

739 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