×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

LoCK all commandbutton in frame1
2

LoCK all commandbutton in frame1

LoCK all commandbutton in frame1

(OP)
Possible to lock all commandbutton in fram1?

RE: LoCK all commandbutton in frame1

Yes.
What have you tried so far?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: LoCK all commandbutton in frame1

(OP)

CODE -->

Private Sub LOOP_FRAME1()

     Dim objControl As Control
     For Each objControl In Frame1.Container
     
     
     Debug.Print objControl.Name
          'If CommandButton Is TextBox Then
               'objControl.enable = True
               'objControl.Visible = True
          'End If
          
     Next objControl

End Sub 

RE: LoCK all commandbutton in frame1

By "lock all commandbutton in fram1" I assume you mean: Set Enabled property to False

CODE

Private Sub LOOP_FRAME1()
Dim c As Control

For Each c In Me.Controls
    If (TypeOf c Is CommandButton) And (c.Container.Name = "Frame1") Then
        c.Enabled = False
    End If
Next c

End Sub 

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: LoCK all commandbutton in frame1

(OP)
Andy, WORK! tks.

but possible to use this code as function?

similar:

CODE -->

Public Sub LOOP_FRAME1(fram)
Dim c As Control

For Each c In Me.Controls
    If (TypeOf c Is CommandButton) And (c.Container.Name = fram) Then
        c.Enabled = False
    End If
Next c

End Sub 

where fram is the name of Frame

RE: LoCK all commandbutton in frame1

You don't need a Function (Functions return a value), simple Sub will do it:
Private sub on the Form:

CODE

Call DisAbleButtonsOnFrame("Frame1")

Private Sub DisAbleButtonsOnFrame(ByRef strFra As String)
Dim c As Control

For Each c In Me.Controls
    If (TypeOf c Is CommandButton) And (c.Container.Name = strFra) Then
        c.Enabled = False
    End If
Next c

End Sub 

Or you could have it as a Public Sub (in a standard Module), but you would have to pass a Form as well, which is not a big deal:

CODE

'Code in the Form
Call DisAbleButtonsOnFrame(Me, "Frame1")

'code in a Module
Public Sub DisAbleButtonsOnFrame(ByRef frm As Form, ByRef strFra As String)
Dim c As Control

For Each c In frm.Controls
    If (TypeOf c Is CommandButton) And (c.Container.Name = strFra) Then
        c.Enabled = False
    End If
Next c

End Sub 

BTW - Use more meaningful names for your Controls.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: LoCK all commandbutton in frame1

(OP)
Please Andy,

can you help me, now with new code?

CODE

Private Sub CONTROLLO_CAMPI_PRENOTAZIONI()

    ER = 0
    lCtr = 0
    For Each CCONT In Me.Controls
        'Debug.Print Val(CCONT.Tag)
        If CCONT.Container Is Me.Frame2 And Val(CCONT.Tag) >= 1 And (TypeOf CCONT Is ComboBox) Then
            SNAME = CCONT.Name
            If CCONT.Text = "" Then
                TG = CCONT.Tag
                Call SELECT_CASE_P(TG)
                ER = ER + 1
            End If
        End If
    Next CCONT

End Sub 

i need to loop only all combobox in frame2 and if the combobox have a tag>=1 then....

actually have error in image:

https://files.engineering.com/getfile.aspx?folder=...

possible causes....

RE: LoCK all commandbutton in frame1

It would help if you showed which line of code the error is occurring on.

(and you really should have Option Explicit by now; I know we've advised this on more than one occasion)

RE: LoCK all commandbutton in frame1

(OP)
If CCONT.Container Is Me.Frame2 And Val(CCONT.Tag) >= 1 And (TypeOf CCONT Is ComboBox) Then

yes, i have option exlplicit in head of my modules and forms

CCONT is a public dim As Control, in a module

RE: LoCK all commandbutton in frame1

In that case, what other controls do you have somewhwere oin the form? As it looks like you have managed to find one that does not have a tag property.

Indeed, if you reinstate your commented out debug line, you should get the same error, only this time the error line will be the debug line.

Don't make the mistake of assuming that the If line will filter out the test for the 'bad' control becasue it is not in Frame2. VB does not do short-circuit evaluations in if statements. Every term is always evaluated.

RE: LoCK all commandbutton in frame1

Ok, so that is completely different code from what you have previously shown. And seems to have very little to do with your original question, given there is not a single commandbutton on the form whatsoever.

And it runs without any error here, annd produces the results I'd expect. What is your issue?

RE: LoCK all commandbutton in frame1

(OP)
Strong, but i need to check only a combobox in frame, and not all....

RE: LoCK all commandbutton in frame1

You are going to have to be much more explicit in your requirements.

Afraid I am not going to guess what you want. Let's start with what do you mean by "check"? And what makes one specific combobox more interesting than the others in the frame, i.e. what identifies the combobox you want to 'check' (and remember you still need to clarify what 'check' means)?

For the sake of camparison, right now, your code is happily identifying any combobox in the frame that has a tag that has a val >=1. And since you set 3 three such comboboxes (assigning them tag of 5), those three are successfully and correctly returned.

RE: LoCK all commandbutton in frame1

I'm Sorry, but the questione on combobox, Is different from this originale post. I have resolved about "lock".
In effect my last questione about looping in frame Is a new question.
Sorry for my mistake.
I post a new question? Or you have undestand, my prob?

RE: LoCK all commandbutton in frame1

New questions should generally always go into new threads

But take the following on board.

Your new 'question' is not really clear yety:

>i need to loop only all combobox in frame2 and if the combobox have a tag>=1 then....
>actually have error

Initially looked like you were looking how to resolve the error

Your follow up:
>I need to check only a combobox in frame, and not all

Well, your attached code example successfully does pretty much exactly that (without any error), so again ... what is it that you want to achieve that your code does not? Although we might sometimes give the impression that we are mind-readers, in reality we are not.

RE: LoCK all commandbutton in frame1

(OP)
To understand me, now i have uploaded a new form present in my project.

The old form is an old zip file, not consider now, please.

if you see in image, all the comboboxes in question are signed in red, because have a tag filled.

the other comboboxes not have a tag filled, and then esclude when code loop the comboboxes.

in effect i need to check if in frame2 are present comboboxes whit a filled tag value.

.... store into one array only the tag value >=1, found in the loop

in my case the array is 1, 2, 3, 4, 5, 6

RE: LoCK all commandbutton in frame1

>i need to check if in frame2 are present comboboxes whit a filled tag value.

But your code associated with your 'old form' pretty much does exactly this already. It then adds a reference to the identified control to a collection (from which you can access the tag values*) rather than the tag value to an array. So AGAIN, what is your problem? Are you saying that whilst you can check the value of the tag (which you are) you don't know how to add it to an array?

And your latest [posted project contains no code to show where you are struggling. Are you expecting us to write everything for you? Surely you know by now that that is not what this site is about? We'll help, sure, but you have to do stuff to help yourself as well.


* Illustrated below with a miniscule modification of your Form_Click event

CODE

Private Sub Form_Click()
    Dim c As Collection
    Set c = FindCombosInFrame2WithTagGeOne
    Dim v As Variant
    
    ' List the ComboBoxes found.
    Debug.Print "Comboboxes in Frame2 with Tag value >= 1:"
    For Each v In c
        If HasIndex(v) Then
            Debug.Print v.Name & "(" & v.Index & ")", v.Tag
        Else
            Debug.Print v.Name, v.Tag
        End If
    Next
End Sub 

RE: LoCK all commandbutton in frame1

Consider this code. It is your code, just cut in a smaller pieces and re-arranged a little:

CODE

Private Sub CONTROLLO_CAMPI_PRENOTAZIONI()

    ER = 0
    lCtr = 0
    For Each CCONT In Me.Controls
        If TypeOf CCONT Is ComboBox Then
            'We are dealing only with ComboBoxes on the Form
            If CCONT.Container Is Me.Frame2 Then
                'ComboBoxes on Frame2 only
                If Val(CCONT.Tag) >= 1 Then
                   'Comboboxes on the Frame 2 with Tag >=1
                    SNAME = CCONT.Name
                    If CCONT.Text = "" Then
                        TG = CCONT.Tag
                        Call SELECT_CASE_P(TG)
                        ER = ER + 1
                    End If
                End If
            End If
        End If
    Next CCONT

End Sub 

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: LoCK all commandbutton in frame1

(OP)
Hi Andy and strongm, with your last code my problem, finally is resolved.
tks for patience, and tks to understand my "Napolitan English"!

If you remember i'm Napolitan!

Pizza?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close