Solved

URGENT:  Textboxes on a Picture Box

Posted on 2006-11-06
4
169 Views
Last Modified: 2010-04-30
Hi All,

If I have 10 textboxes on a form as well as two pictureboxes

3 are located in  picturebox1, 3 are located in picturebox2

4 are outside of the pictureboxes and are just on the form

How can I enable and disable the textboxes inside picturebox1 using a for ... next loop ?

MTIA

Darrin
0
Comment
Question by:dwe0608
4 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 17880294
Hi dwe0608,

Private Sub Command1_Click()
    EnableDisableTextboxes False, Picture1
End Sub

Private Sub EnableDisableTextboxes(ByVal Status As Boolean, ByRef ContainedIn As PictureBox)
    Dim txt As Control
    For Each txt In Me.Controls
        If txt.Container Is ContainedIn Then txt.Enabled = False
    Next
End Sub

For example, just call as EnableDisableTextBoxes True,Picture1  to enable and ... False,Picture1 to disable

For example

Tim Cottee
0
 
LVL 1

Author Comment

by:dwe0608
ID: 17880353
And if I wanted to enable all textboxes - the following code marked by  ?? would be helpful

Private Sub EnableDisableTextboxes(ByVal Status As Boolean, optional ByRef ContainedIn As PictureBox = nothing)
    Dim txt As Control
    For Each txt In Me.Controls
       if not Ismissing(ContainedIn) and ?? not containedin is nothing ?? then
           If txt.Container Is ContainedIn Then txt.Enabled = False
       else
           txt.Enabled = False
       end if
    Next
End Sub


MTIA

Darrin
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 17880452
Tim already give you the solution, the only thing he should use status to set the enabled flag

ie.


Private Sub EnableDisableTextboxes(ByVal Status As Boolean, Optional ByRef ContainedIn As PictureBox = Nothing)
    Dim txt As Control
    For Each txt In Me.Controls
       If Not IsMissing(ContainedIn) And Not ContainedIn Is Nothing Then
           If txt.Container Is ContainedIn Then txt.Enabled = Status
       End If
    Next
End Sub
0
 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
ID: 17887701
i got what u want darrin...

here's your code

Private Sub EnableDisableTextboxes(ByVal Status As Boolean, Optional ByRef ContainedIn As PictureBox = Nothing)
    Dim txt As Control
    For Each txt In Me.Controls
        If ContainedIn Is Nothing Then
            txt.Enabled = Status
        Else
            If txt.Container Is ContainedIn Then txt.Enabled = Status Else txt.Enabled = Not Status
        End If
    Next
End Sub

if call the function in the following way:

to disable textboxes contained in a specific picture box u call:
EnableDisableTextboxes False, Picture1 'false because u want to disable them, if u want to re-enable them u just set this to true

if u want to disable all textboxes u just call
EnableDisableTextboxes False 'or True to re-enable all textboxes on your form

hope this helps

cheers,

Dan

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

839 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