Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LoCK all commandbutton in frame1 2

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
425
IT
Possible to lock all commandbutton in fram1?
 
Yes.
What have you tried so far?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
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
 
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
 
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
 
You don't need a Function (Functions return a value), simple Sub will do it:
Private sub on the Form:

Code:
Call DisAbleButtonsOnFrame("Frame1")
[blue]
Private [/blue]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:
[green]'Code in the Form[/green]
Call DisAbleButtonsOnFrame(Me, "Frame1")

[green]'code in a Module[/green]
[blue]Public[/blue] 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
 
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:


possible causes....
 
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)
 
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
 
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.
 
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?
 
Strong, but i need to check only a combobox in frame, and not all....
 
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.

 
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?
 
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.

 
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
 
 https://files.engineering.com/getfile.aspx?folder=53c49804-e6da-402c-a56b-aa7fe61b4800&file=TEST.zip
>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:
[blue]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 & ")"[b][COLOR=red], v.Tag[/color][/b]
        Else
            Debug.Print v.Name[b][COLOR=red], v.Tag[/color][/b]
        End If
    Next
End Sub[/blue]
 
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[green]
            'We are dealing only with ComboBoxes on the Form[/green]
            If CCONT.Container Is Me.Frame2 Then[green]
                'ComboBoxes on Frame2 only[/green]
                If Val(CCONT.Tag) >= 1 Then[green]
                   'Comboboxes on the Frame 2 with Tag >=1[/green]
                    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
 
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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top