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
Solved

Dynamic Picture box, button...

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

808 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