Solved

How can I enable few buttons in few forms?

Posted on 2003-12-11
11
298 Views
Last Modified: 2012-05-04
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.
0
Comment
Question by:hjaaban
  • 4
  • 2
  • 2
  • +1
11 Comments
 
LVL 3

Expert Comment

by:sohilm
ID: 9920413
pretty simple actually, all you have to do is in the form load event type in cmdDelete.Enabled = true.

Thanks
Sohil
0
 
LVL 3

Expert Comment

by:sohilm
ID: 9920445
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.
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9920468
private sub EnableDelete()
Dim fun As CommandButton

For Each fun In Controls
    If fun.Name = "cmdDelete" Then fun.Enabled = False
Next
End Sub
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9920473
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:hjaaban
ID: 9920925
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.
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9920977
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
0
 

Author Comment

by:hjaaban
ID: 9921826
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?
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 50 total points
ID: 9921858
you cant change an unloaded form at runtime unless you load all the forms at runtime and then run the procedure

or just put the control loop on every form load you wanna enable the button
0
 
LVL 1

Expert Comment

by:Dameon1
ID: 10180355
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.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now