PDA

View Full Version : Solved: Problem with Project User form



oharris
08-14-2006, 02:24 PM
Hello all,
I am trying to create a piece of code that sets some variables for a user form, then opens that form, then returns the value chosen. I tried to use properties as detailed here (http://www.peltiertech.com/Excel/PropertyProcedures.html), but I can't get the form to open. I used the code as in the sample and I tried to use Load Form, and neither works. It seemed to take the property code, but it sure doesn't work. Any idea how to do this? Thanks in advance

lucas
08-14-2006, 04:52 PM
Hi oharris,
I'm going to move this to the excel users forum as I think you will find more help there since this appears to be an excel quesion judging from the link.

As far as getting your form to show....
you will need to insert a module and add the showform code to it:
userform1 is the name of your userform in this example.

Sub showform()
UserForm1.Show
End Sub


it would really help if you could upload what you have so far. Please let us know if I was wrong and this is not for excel. To attach your file...hit post reply and then look for manage attachments below the posting area.

example attached.

oharris
08-15-2006, 07:34 AM
It is a Project 2003 question, but that was the only example I could find for passing data to and returning data from forms was the excel example I linked to.

With respect to your userform.show code, I tried that and at first it worked, but after I added the property code, it wouldn't work any more. I even removed the property code and it still doesn't work. When I try to execute it, it gives me a type mismatch error. I then hit debug and when I mouse over the the highlighted line, it says "Object Variable or With block variable not set." It's as though I've mispelled the name of the form, but I've checked and rechecked that. Any ideas what could cause this?

lucas
08-15-2006, 07:39 AM
could you post the property code you used?

oharris
08-15-2006, 08:16 AM
OK, I can't post the actual files, but let me start by explaining what this form is supposed to do.

As I said, the code takes inputs from an Excel spreadsheet and imports them into a project file. In the Project file, Categories are Level 1 tasks, and Events are Level 2 tasks. When an event is listed that doesn't match the name of an existing event, the form is supposed to list all the Events (Level 2 tasks) under a given category (Level 1 task) and let the user choose between creating a new event with the new name or using an existing event. The inputs are category name and the event name, and the output is the chosen task whether its a new one created in the form of one chosen from the list.

The code for the properties is:

Public Property Get ChosenTask() As Task
'This is the output chosen task

End Property

Public Property Let TaskName(ByVal strName as String)
'This is the event name that wasn't found to match in a previous piece of code

With Me
.lblTtile.Caption = "Event " & strName & " was not found. You must either crteate a new event or choose an existing event."
.txtNewName.Value = strName
End With

End Property

Public Property Let Category(ByVal strCatName as string)

End Property



I've tried various methods of calling the code, but none of them work. What I'm trying to do is set the two properties, then show the form, then retreive the task returned by the form.

lucas
08-15-2006, 08:28 AM
Oharris,
I don't have project installed so would it be possible for you to set up an excel file with your form. Maybe if we can duplicate the problem in excel we can figure out what is going on in project.....

Just a simple example in excel where you change the properties ect. You could post that here and we can take a look

lucas
08-15-2006, 08:29 AM
I don't see anything obvious in your properties code that would cause the problem you describe.

Bob Phillips
08-15-2006, 08:35 AM
Presumably, your properties are within a class. So you need in instantiate the class



Set myObj = New Class1


the reference the properties via the class object



myObj.ChosenTask = "Task 1"
myObj.taskName = "Work Harder"

oharris
08-16-2006, 09:15 AM
Oharris,
I don't have project installed so would it be possible for you to set up an excel file with your form. Maybe if we can duplicate the problem in excel we can figure out what is going on in project.....

Just a simple example in excel where you change the properties ect. You could post that here and we can take a look

lucas,
Sorry it took me so long to respond, I got busy yesterday and didn't get back to this. I tried to do as you say and make an excel file that does the same thing. Of course it worked just fine.:banghead: Any other ideas?

oharris
08-16-2006, 09:19 AM
Presumably, your properties are within a class. So you need in instantiate the class



Set myObj = New Class1


the reference the properties via the class object



myObj.ChosenTask = "Task 1"
myObj.taskName = "Work Harder"


The properties are in the userform. I did try to instantiate the form as shown:

set fChooseEvent = new frmChooseEvent


but it bombs on that line. The form is named frmChooseEvent, but every time I reference it, it acts like it doesn't exist. Any ideas?

lucas
08-16-2006, 09:26 AM
When you say it bombs do you get a type mismatch....that would indicate a spelling error possibly. It must be exact and the form must exist. Hopefully Bob(XLD) is still monitoring this and can give some insights also.

Bob Phillips
08-16-2006, 09:35 AM
When you have properties within a form class, you need to load the form to create an instance (unlike ordinary class modules), and then assign the properties.

Something like this



Load frmChooseEvent
frmChooseEvent.ChosenTask = "Task 1"
frmChooseEvent.TaskName = "Work Harder"

oharris
08-16-2006, 09:51 AM
When you say it bombs do you get a type mismatch....that would indicate a spelling error possibly. It must be exact and the form must exist. Hopefully Bob(XLD) is still monitoring this and can give some insights also.

Yes, it gives a type mismatch. It's exactly as though I have a spelling error. I have gone so far as to copy the name out of the properties box and paste it into my code, but it still acts as though it doesn't exist. Is there something I need to do to get it to see the form?

oharris
08-16-2006, 09:52 AM
When you have properties within a form class, you need to load the form to create an instance (unlike ordinary class modules), and then assign the properties.

Something like this



Load frmChooseEvent
frmChooseEvent.ChosenTask = "Task 1"
frmChooseEvent.TaskName = "Work Harder"


Yup, I have done that. It bombs on the first line.

lucas
08-16-2006, 10:13 AM
Couple of thoughts:
can you run the form directly....not calling it from a sub. By clicking in the code for the form and hit run..?

Will it run if you remove the properties code?

Bob Phillips
08-16-2006, 10:52 AM
Yup, I have done that. It bombs on the first line.

That doesn't make sense. I think you are going to have to post a workbook.

oharris
08-16-2006, 10:55 AM
OK now we're getting somewhere. I tried to open the form directly and it gave the same error. I then started looking at the code in the form, and I tried commenting out a subroutine call in the initialize event that loaded a combo box and voila it started working. So, evidently, my problem is with that subroutine call. Thank you so much for sticking with me though this. I think I can chase it down from here. Thank you both so much!

lucas
08-16-2006, 11:05 AM
Be sure to mark your thread solved after you check everything. Use thread tools at the top of the page.

oharris
08-16-2006, 11:34 AM
Thread marked! The problem with activating the form has been identified. If I can't solve the problem with the subroutine call, I will start a new thread. Thanks again for all your help. This is a great forum.:thumb