hjaaban
asked on
How can I enable few buttons in few forms?
In VB6 few forms does include a button called cmdDelete, few other do not include this button. On main form load I would like to run some code to enable cmdDelete wherever it is found in a form. cmdDelete.enabled is been set to False in design time, so I need to change it to True during run time.
Any idea?
HJ.
Any idea?
HJ.
oops misunderstood. Try this logic.
Go through all child forms (not sure of vb6 but in .net there is an mdichildren container you can interate through).
For each child form go through all controls (there shuold be a control container).
Check the name of the control contaiter to see if it is cmddelete
if so just enable it.
Hope this helps.
Go through all child forms (not sure of vb6 but in .net there is an mdichildren container you can interate through).
For each child form go through all controls (there shuold be a control container).
Check the name of the control contaiter to see if it is cmddelete
if so just enable it.
Hope this helps.
private sub EnableDelete()
Dim fun As CommandButton
For Each fun In Controls
If fun.Name = "cmdDelete" Then fun.Enabled = False
Next
End Sub
Dim fun As CommandButton
For Each fun In Controls
If fun.Name = "cmdDelete" Then fun.Enabled = False
Next
End Sub
put in in form_Load
private sub EnableDelete()
Dim fun As CommandButton
For Each fun In Controls
If fun.Name = "cmdDelete" Then fun.Enabled = False
Next
End Sub
private sub EnableDelete()
Dim fun As CommandButton
For Each fun In Controls
If fun.Name = "cmdDelete" Then fun.Enabled = False
Next
End Sub
ASKER
Mikal613,
you are close to give me answer, but I get error message says Type mismatch for fun.
Also I need to run code to scan all forms that include cmdDelete and skip those which don't include cmdDelete.
Any new?
HJ.
you are close to give me answer, but I get error message says Type mismatch for fun.
Also I need to run code to scan all forms that include cmdDelete and skip those which don't include cmdDelete.
Any new?
HJ.
dim frm as Form
dim fun as Control
for each frm in forms
for each fun in controls
if fun.Name = "CmdDelete" then
fun.enabled = False
end if
next
next
dim fun as Control
for each frm in forms
for each fun in controls
if fun.Name = "CmdDelete" then
fun.enabled = False
end if
next
next
ASKER
The following code compiles and runs:
Dim frm As Form
Dim fun As Control
For Each frm In Forms
For Each fun In frm
If fun.Name = "cmdDelete" Then
frm.cmdDelete.Enabled = True
End If
Next
Next
But I don't know why unloaded forms are not be effected by the above code.
for example: form frmstudent does not change the status of cdmDelete button, unless I open it and run the code again.
any idea how can I make all forms (loaded and unloaded) take changes?
Dim frm As Form
Dim fun As Control
For Each frm In Forms
For Each fun In frm
If fun.Name = "cmdDelete" Then
frm.cmdDelete.Enabled = True
End If
Next
Next
But I don't know why unloaded forms are not be effected by the above code.
for example: form frmstudent does not change the status of cdmDelete button, unless I open it and run the code again.
any idea how can I make all forms (loaded and unloaded) take changes?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Of course you could have an EnableDelets sub on all of the forms with the button. You wouldn't have to loop.
In forms:
Sub EnableDelete
cmddelete.enabled = true
End Sub
To enable all delete buttons:
Sub EnableAllDeletes
frmA.enabledelete
frmb.enabledelete
...
End SUb
If neccesary you could have the forms with delete buttons added to a collection. You could then loop through the collection and do EnableDelete on each one instead of using the sub above.
In forms:
Sub EnableDelete
cmddelete.enabled = true
End Sub
To enable all delete buttons:
Sub EnableAllDeletes
frmA.enabledelete
frmb.enabledelete
...
End SUb
If neccesary you could have the forms with delete buttons added to a collection. You could then loop through the collection and do EnableDelete on each one instead of using the sub above.
Thanks
Sohil