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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open a global form in vb (MS Project 2010)

Status
Not open for further replies.

remeng

Technical User
Jul 27, 2006
504
0
16
US
Hi all;

I am trying to open a global form from the quick launch ribbon. I have created the form named "calculate". I have written the script to open the form up, however, when I execute the form, the Task Information screen opens instead of the form I am calling. I have changed the form name to see if there are any conflicts, but the same thing happens. I have tried the oncmd.openform command, but nothing happens except an error. Here is the current code.

Code:
Public Sub open_form()

form("calculate")

End Sub


The form is located under Global.MPT

Thank you for the assist.
 
>Project 2010 does not support creating or using custom forms

It doesn't even support them if you loaded an older version of Project that has existing custom forms.

So I can only assume that you must actually be referring to a VBA User Form (a somewhat different beast) - and these are not shown in the same way as the old custom forms. e.g.

Load calculate
calculate.Show
 
HI strongm,

thanks! That was exactly it.

I knew it was something really simple. Now however, when I click the close button with the Unload calculate command that previously worked, it doesn't. What is causing the new error?

Thanks,

Mike
 
Here is all the code:

Code:
Sub open_calculate()
    
   Load calculate
   calculate.Show
    
    
End Sub

Code:
Private Sub calculate_Click()


'_________________________

' Days to Hours (8 hours = 1 day)


If day_box1 = "" Then

hour_box1 = ""

ElseIf IsNumeric(day_box1) = True Then

        If day_box1 > 0 Then
        
        hour_box1 = Format(day_box1 * 8, "0.000")
        
        
        ElseIf day_box1 = 0 Then
        
        hour_box1 = 0
        
        
        ElseIf day_box1 < 0 Then
        
        hour_box1 = "Value < 0"

        End If
ElseIf IsNumeric(day_box1) = False Then

End If

'_________________________

' Hours to Days (8 hours = 1 day)


If hour_box2 = "" Then

day_box2 = ""

ElseIf IsNumeric(hour_box2) = True Then


        If hour_box2 > 0 Then
        
        day_box2 = Format(hour_box2 / 8, "0.000")
        
        
        ElseIf hour_box2 = 0 Then
        
        day_box2 = 0
        
        
        ElseIf hour_box2 < 0 Then
        
        day_box2 = "Value < 0"
        
        End If

ElseIf IsNumeric(hour_box2) = False Then

End If

'_________________________

' Days to % Hours (8 hours = 1 day)


If day_percent_enter = "" Then

percent_hour_return = ""

ElseIf IsNumeric(day_percent_enter) = True Then

        If day_percent_enter > 0 Then
        
        percent_hour_return = Format((day_percent_enter) * 100, "0")
        
        ElseIf day_percent_enter < 0 Then
        
        percent_hour_return = "Value < 0"
        
        End If

ElseIf IsNumeric(day_percent_enter) = False Then

End If

 
'_________________________

' Hours to % days (8 hours = 1 day)


If hour_percent_enter = "" Then

percent_day_return = ""

ElseIf IsNumeric(hour_percent_enter) = True Then

        If hour_percent_enter > 0 Then
        
        percent_day_return = Format((hour_percent_enter) / 8 * 100, "0")
 
        ElseIf hour_percent_enter < 0 Then
        
        percent_day_return = "Value < 0"
        
        End If

ElseIf IsNumeric(hou_percent_enter) = False Then

End If

'_____________________________________________________________________
'_____________________________________________________________________

'Days to hours (24 hours = 1 day)


If day_box1_24 = "" Then

hour_box1_24 = ""

ElseIf IsNumeric(day_box1_24) = True Then

        If day_box1_24 > 0 Then
        
        hour_box1_24 = Format(day_box1_24 * 24, "0.000")
        
        
        ElseIf day_box1_24 = 0 Then
        
        hour_box1_24 = 0
        
        
        ElseIf day_box1_24 < 0 Then
        
        hour_box1_24 = "Value < 0"
        
        End If

ElseIf IsNumeric(day_box1_24) = False Then

End If

'_________________________

' Hours to Days (24 hours = 1 day)


If hour_box2_24 = "" Then

day_box2_24 = ""

ElseIf IsNumeric(hour_box2_24) = True Then

        If hour_box2_24 > 0 Then
        
        day_box2_24 = Format(hour_box2_24 / 24, "0.000")
        
        
        ElseIf hour_box2_24 = 0 Then
        
        day_box2_24 = 0
        
        
        ElseIf hour_box2_24 < 0 Then
        
        day_box2_24 = "Value < 0"
                
        End If

ElseIf IsNumeric(day_box2_24) = False Then

End If

'_________________________

' Days to % Hours (24 hours = 1 day)


If day_percent_enter_24 = "" Then

hour_percent_return_24 = ""

ElseIf IsNumeric(day_percent_enter_24) = True Then

        If day_percent_enter_24 > 0 Then
        
        hour_percent_return_24 = Format((day_percent_enter_24) * 100, "0")
        
        ElseIf day_percent_enter_24 < 0 Then
        
        hour_percent_return_24 = "Value < 0"
        
        End If
 
 ElseIf IsNumeric(day_percent_enter_24) = False Then
 
 End If
 
'_________________________

' Hours to % days (24 hours = 1 day)


If hour_percent_enter_24 = "" Then

day_percent_return_24 = ""

ElseIf IsNumeric(hour_percent_enter_24) = True Then

        If hour_percent_enter_24 > 0 Then
        
        day_percent_return_24 = Format((hour_percent_enter_24) / 24 * 100, "0")
        
        ElseIf hour_percent_enter_24 < 0 Then
        
        day_percent_return_24 = "Value < 0"
        
        End If

ElseIf IsNumeric(hour_percent_enter_24) = False Then

End If

End Sub

Code:
Private Sub close_button_Click()

'closes the calculator

Unload calculate



End Sub

Code:
Private Sub reset_button_Click()

'Reset all fields

day_box1 = ""
hour_box1 = ""
hour_box2 = ""
day_box2 = ""
day_percent_enter = ""
percent_hour_return = ""
hour_percent_enter = ""
percent_day_return = ""
day_box1_24 = ""
hour_box1_24 = ""
hour_box2_24 = ""
day_box2_24 = ""
day_percent_enter_24 = ""
hour_percent_enter_24 = ""
day_percent_return_24 = ""
hour_percent_return_24 = ""


End Sub

 
You have a Form named "calculate", so I understand you can do:
[tt]
Load calculate
calculate.Show
[/tt]
What I do not understand is: "when I click the close button with the Unload calculate command that previously worked, it doesn't. What is causing the new error?"

In your code when you state:
[tt]
Unload calculate
[/tt]
You just unloading your Form "calculate". That's it.
What do you want to happen when [tt]Unload calculate[/tt] line of code is run?

Have fun.

---- Andy
 
Before I used the Load command, when I use the close button, the Unload command would actually close the form which is what I want to happen. Is there a second command that I need to add that will close the form before it unloads?
 
...Hide the Form and Unload it, unless you have any code after the Unload, which may reload the Form again just to excecute the lines of code after Unload.

"the Unload command would actually close the form which is what I want to happen"
So it is NOT what happens now? What does it do?

Have fun.

---- Andy
 
Hi Andy,

I get a run time error 361 "Can't load or unload this object". When I go to debug,
Code:
Unload calculate
is the highlighted code.

Code:
Private Sub close_button_Click()

'closes the calculator

Unload calculate



End Sub

Thanks,

Mike
 
I figured it out. The code solution is:

Code:
Unload Me
 
>Private Sub [red]calculate[/red]_Click()

You have a control, a button, on the form that has the same name as the form. Unload is trying to unload it ... hence the error message.
 
And that's why I always use prefixes: frmSomeForm for Form, cmdButton for command buttons, optMyOption for option buttons, lblABC for labels, etc.

Have fun.

---- Andy
 
Thanks Andy for the great naming convention tip. I made the change just so that later on I don't forget it. I was wondering, is there a way to clean this code up or should I just leave it as is?

Code:
Private Sub reset_button_Click()

'Reset all fields

day_box1 = ""
hour_box1 = ""
hour_box2 = ""
day_box2 = ""
day_percent_enter = ""
percent_hour_return = ""
hour_percent_enter = ""
percent_day_return = ""
day_box1_24 = ""
hour_box1_24 = ""
hour_box2_24 = ""
day_box2_24 = ""
day_percent_enter_24 = ""
hour_percent_enter_24 = ""
day_percent_return_24 = ""
hour_percent_return_24 = ""


End Sub
 
Assuming that you want to reset all the text controls on the form ...

Code:
[blue]Private Sub Reset_Click()
    Dim myControl As Control
    For Each myControl In Controls
        If TypeName(myControl) = "TextBox" Then myControl.Text = ""
    Next
End Sub[/blue]
 
I do what all the text boxes to be reset. Thank you strongm. That worked. I have one more question. I noticed that when I open the macro via a button on the ribbon and I am just using a local file it works and launches the macro. When I am connected to a EPM server the ribbon button does not work. The macro is saved in the Global.MPT location. I also noticed that the macro name also changes to Global.MPT!open_calculator from open_calculator (local and not connected to the server). Is there a way to make the ribbon button open the macro while either local or connected to the server?
 
Afraid I'm not familiar enough with Project and it's interaction with EPM to be able to comment
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top