Consulting

Results 1 to 19 of 19

Thread: Solved: Problem with Project User form

  1. #1
    VBAX Regular
    Joined
    Jul 2006
    Posts
    14
    Location

    Solved: Problem with Project User form

    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, 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

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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.
    [vba]
    Sub showform()
    UserForm1.Show
    End Sub
    [/vba]

    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.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Regular
    Joined
    Jul 2006
    Posts
    14
    Location
    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?

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    could you post the property code you used?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Regular
    Joined
    Jul 2006
    Posts
    14
    Location
    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:
    [vba]
    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

    [/vba]

    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.

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I don't see anything obvious in your properties code that would cause the problem you describe.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Presumably, your properties are within a class. So you need in instantiate the class

    [vba]

    Set myObj = New Class1
    [/vba]

    the reference the properties via the class object

    [vba]

    myObj.ChosenTask = "Task 1"
    myObj.taskName = "Work Harder"
    [/vba]

  9. #9
    VBAX Regular
    Joined
    Jul 2006
    Posts
    14
    Location
    Quote Originally Posted by lucas
    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. Any other ideas?

  10. #10
    VBAX Regular
    Joined
    Jul 2006
    Posts
    14
    Location
    Quote Originally Posted by xld
    Presumably, your properties are within a class. So you need in instantiate the class

    [vba]

    Set myObj = New Class1
    [/vba]

    the reference the properties via the class object

    [vba]

    myObj.ChosenTask = "Task 1"
    myObj.taskName = "Work Harder"
    [/vba]
    The properties are in the userform. I did try to instantiate the form as shown:
    [VBA]
    set fChooseEvent = new frmChooseEvent
    [/VBA]

    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?

  11. #11
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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

    [vba]

    Load frmChooseEvent
    frmChooseEvent.ChosenTask = "Task 1"
    frmChooseEvent.TaskName = "Work Harder"
    [/vba]

  13. #13
    VBAX Regular
    Joined
    Jul 2006
    Posts
    14
    Location
    Quote Originally Posted by lucas
    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?
    Last edited by oharris; 08-16-2006 at 10:10 AM.

  14. #14
    VBAX Regular
    Joined
    Jul 2006
    Posts
    14
    Location
    Quote Originally Posted by xld
    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

    [vba]

    Load frmChooseEvent
    frmChooseEvent.ChosenTask = "Task 1"
    frmChooseEvent.TaskName = "Work Harder"
    [/vba]
    Yup, I have done that. It bombs on the first line.

  15. #15
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  16. #16
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by oharris
    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.

  17. #17
    VBAX Regular
    Joined
    Jul 2006
    Posts
    14
    Location
    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!

  18. #18
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Be sure to mark your thread solved after you check everything. Use thread tools at the top of the page.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  19. #19
    VBAX Regular
    Joined
    Jul 2006
    Posts
    14
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •