Consulting

Results 1 to 17 of 17

Thread: Solved: Options into a combobox?

  1. #1
    VBAX Regular
    Joined
    Sep 2009
    Posts
    36
    Location

    Question Solved: Options into a combobox?

    Hey, me again.

    I was just wondering, if I had a slide with options to select, through check boxes, could I code the answers to appear in a combobox in another slide.

    For example: Someone has the option to pick a bluray disc drive, an external mouse, a wireless router, a printer. Their results will either be none of the above, up to all four.

    So, can I put their answers into a combobox instead of 4 labels? Thanks.

  2. #2
    VBAX Regular
    Joined
    Sep 2009
    Posts
    36
    Location
    Okay so I have tried the following code, but everytime the powerpoint is run the options are all added on again. So I end up with the same options over and over and over again. The code is under a command button on a previous slide, which attempts to add their answers to the combobox. Know what I am doing wrong? Should it be a listbox?
    [VBA]Private Sub CommandButton1_Click()
    If Slide16.ComboBox1.ListCount <= 4 Then
    With Slide16.ComboBox1
    If Slide13.CheckBox1.Value = True Then Slide16.ComboBox1.AddItem "Wireless Mouse - £25"
    If Slide13.CheckBox2.Value = True Then Slide16.ComboBox1.AddItem "Canon Printer - £50"
    If Slide13.CheckBox3.Value = True Then Slide16.ComboBox1.AddItem "Integrated Webcam - £30"
    If Slide13.CheckBox4.Value = True Then Slide16.ComboBox1.AddItem "Blu Ray Drive - £60"
    End With
    End If
    SlideShowWindows(1).View.GotoSlide (6)
    End Sub[/VBA]
    Sorry for the double post, just thought I'd get you guys more information.

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Try:

    [vba]With Slide16.ComboBox1
    .Clear
    If Slide13.CheckBox1.Value = True Then .AddItem "Wireless Mouse - £25"
    If Slide13.CheckBox2.Value = True Then .AddItem "Canon Printer - £50"
    If Slide13.CheckBox3.Value = True Then .AddItem "Integrated Webcam - £30"
    If Slide13.CheckBox4.Value = True Then .AddItem "Blu Ray Drive - £60"
    End With[/vba]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    VBAX Regular
    Joined
    Sep 2009
    Posts
    36
    Location
    I tried that, but everytime you load the powerpoint it adds more and more and more, I only every want a minimum of 0 and maximum of 4 in the combobox. Will a listbox work better? Do you understand what I am asking by the way, sorry if it is a little sketchy.

    EDIT: Okay yeah that works fine. Was wondering, does the list box list everything without a drop down menu? Maybe that is what I should be using instead, as I want to show them their choices, not give them another option per say. What do you think?
    Last edited by jamieCR9; 10-20-2009 at 03:46 PM.

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    If you just want to SHOW them their choices just use a normal ppt shape.
    code would look like this (change text, slide number and shape number)

    [VBA]Dim strChoose As String
    Private Sub CommandButton1_Click()

    If Me.CheckBox1 = True Then strChoose = strChoose & "Wireless mouse" & vbCrLf
    If Me.CheckBox2 = True Then strChoose = strChoose & "Canon printer" & vbCrLf
    ActivePresentation.Slides(2).Shapes(3).TextFrame.TextRange = strChoose
    End Sub[/VBA]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    VBAX Regular
    Joined
    Sep 2009
    Posts
    36
    Location
    Quote Originally Posted by John Wilson
    If you just want to SHOW them their choices just use a normal ppt shape.
    code would look like this (change text, slide number and shape number)

    [vba]Dim strChoose As String
    Private Sub CommandButton1_Click()

    If Me.CheckBox1 = True Then strChoose = strChoose & "Wireless mouse" & vbCrLf
    If Me.CheckBox2 = True Then strChoose = strChoose & "Canon printer" & vbCrLf
    ActivePresentation.Slides(2).Shapes(3).TextFrame.TextRange = strChoose
    End Sub[/vba]
    I'll let you know how it goes, thanks.

  7. #7
    VBAX Regular
    Joined
    Sep 2009
    Posts
    36
    Location
    [VBA]Dim strChoose As String
    Private Sub CommandButton1_Click()
    If Me.CheckBox1 = True Then strChoose = strChoose & "Wireless mouse" & vbCrLf
    If Me.CheckBox2 = True Then strChoose = strChoose & "Canon printer" & vbCrLf
    If Me.CheckBox3 = True Then strChoose = strChoose & "Webcam" & vbCrLf
    If Me.CheckBox4 = True Then strChoose = strChoose & "Blu Ray Drive" & vbCrLf
    ActivePresentation.Slides(16).Shapes(1).TextFrame.TextRange = strChoose
    End Sub[/VBA]
    That is what I have, but there is an error with the bottom line. Is that the slide index number or the slideID, as in the VBA slide number? Also, how do I know what number a regular shape is?

    I really do appreciate the help, just trying to add finishing touches.

  8. #8
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    The Slides(xx) should be the index ie Slides (16) is the sixteenth slide in the presentation. The slide object number (what you are calling the vba number I think) is usually the sixteenth slide added to the presentation often not the same thing.

    The easiest way to get the shape number in pre 2007 is to give it an animation the name (eg rectangle 4) in the animation pane will indicate the number. In 2007 the selection pane will indicate where the shape comes in the order. Alternatively select the shape and run this code which will work in all versions.

    MsgBox ActiveWindow.Selection.ShapeRange(1).ZOrderPosition

    Be aware that if you delete shapes or move shapes back or forwards the number may change.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  9. #9
    VBAX Regular
    Joined
    Sep 2009
    Posts
    36
    Location
    No longer relevent...

    [Can't find delete button?]
    Last edited by jamieCR9; 10-21-2009 at 05:37 PM. Reason: delete?

  10. #10
    VBAX Regular
    Joined
    Sep 2009
    Posts
    36
    Location
    Right only one problem now, that is the same as what happened with the original combobox. Every time you press the command button the values are added over and over again. Code:
    [VBA]Dim strChoose As String
    Private Sub CommandButton1_Click()
    If Me.CheckBox1 = True Then strChoose = strChoose & "Wireless mouse" & vbCrLf
    If Me.CheckBox2 = True Then strChoose = strChoose & "Canon printer" & vbCrLf
    If Me.CheckBox3 = True Then strChoose = strChoose & "Webcam" & vbCrLf
    If Me.CheckBox4 = True Then strChoose = strChoose & "Blu Ray Drive" & vbCrLf
    ActivePresentation.Slides(16).Shapes("myshape").TextFrame.TextRange = strChoose
    End Sub[/VBA]
    You really are a legend mate!

  11. #11
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    My mistake and yes naming the shape is good!

    [vba]
    Private Sub CommandButton1_Click()
    Dim strChoose As String 'sets to no text
    If Me.CheckBox1 = True Then strChoose = strChoose & "Wireless mouse" & vbCrLf
    If Me.CheckBox2 = True Then strChoose = strChoose & "Canon printer" & vbCrLf
    If Me.CheckBox3 = True Then strChoose = strChoose & "Webcam" & vbCrLf
    If Me.CheckBox4 = True Then strChoose = strChoose & "Blu Ray Drive" & vbCrLf
    ActivePresentation.Slides(16).Shapes("myshape").TextFrame.TextRange = strChoose
    End Sub[/vba]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  12. #12
    VBAX Regular
    Joined
    Sep 2009
    Posts
    36
    Location
    Quote Originally Posted by John Wilson
    My mistake and yes naming the shape is good!

    [vba]
    Private Sub CommandButton1_Click()
    Dim strChoose As String 'sets to no text
    If Me.CheckBox1 = True Then strChoose = strChoose & "Wireless mouse" & vbCrLf
    If Me.CheckBox2 = True Then strChoose = strChoose & "Canon printer" & vbCrLf
    If Me.CheckBox3 = True Then strChoose = strChoose & "Webcam" & vbCrLf
    If Me.CheckBox4 = True Then strChoose = strChoose & "Blu Ray Drive" & vbCrLf
    ActivePresentation.Slides(16).Shapes("myshape").TextFrame.TextRange = strChoose
    End Sub[/vba]
    Thanks for everything. A little off the same topic, but is there any code which you can put under a command button which resets all the VBA user textbox/option button value/checkbox values entries, leaving all the text boxes empty etc. for the next user of the powerpoint?
    Last edited by jamieCR9; 10-23-2009 at 07:51 AM.

  13. #13
    VBAX Regular
    Joined
    Sep 2009
    Posts
    36
    Location
    Since I can't edit my last post, all I need is the code to end the powerpoint. I tried to work it out/find it, but I can't see where it is. I don't want to have to use the action button, as I would rather the command button on the last slide run the function.

  14. #14
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    SlideShowWindows(1).View.Exit ?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  15. #15
    VBAX Regular
    Joined
    Sep 2009
    Posts
    36
    Location
    Quote Originally Posted by John Wilson
    SlideShowWindows(1).View.Exit ?
    Tried SlideShowWindows(1).View.EndNamedShow, as the exit one didn't come up, and mine didn't work either.

  16. #16
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    EndNamedShow is for Custom Shows it's Exit!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  17. #17
    VBAX Regular
    Joined
    Sep 2009
    Posts
    36
    Location
    I fail at life, thanks John.

Posting Permissions

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