VBA Controls, when value changes boxes not enabled

J

Julibee

I'm working on a prototype for a system and I'm doing it in Powerpoint (OK,
that might have been my first mistake). It lets me mockup screens easily,
and I can demonstrate the flow, and easily change the order of the screens if
I want to.

I have a combo box on a slide. Based on the value selected by the user
(yes/no) I want other boxes to appear. There are 3 different sets of boxes
and labels that could appear depending on the value, and I've put them all in
the same space on my slide. (saving screen real estate and making it easier
for the client to fill data in is my goal here).

I have used the controls toolbar to put the various boxes on my slide. I
have a Setup button (command button) that loads the combo box values using
AddItem, and sets the various box properties .visible=False and .value="" (or
whatever initial value they should have).

I have a WhateverComboBox_Change() sub that checks the value in a simple If
statement, and when triggered the label and text box properties are set
..visible=true.

When I make a choice from the combo box in Slide Show mode, the labels and
text boxes do appear, but they are not enabled. I have added the property
..enabled=True to the code, but it hasn't fixed it.

They seem to work at some times and not at others. I'm using the same
technique in several places, and I get different results - despite copying
and pasting the code so I know I'm doing it the same way. I seem to have
more trouble on slides where I've used this several times.
 
J

Julibee

I think I have the answer - I need to redraw the screen to make it work. It
has been about 20 years since I've done any real programming and I'm a VBA
newbie, so took a while to realize it.

Just to clarify - the behaviour I expected was: I choose an option from the
combo box, the text box appears, I click on it and type the data.

What I was getting was: I choose an option from the combo box, the text box
appears, I click on it and my cursor does not change to the I bar (still a
pointer) and I can't type text into the box.

It was particularly confusing because sometimes it did work - the first time
I ran the slideshow this morning it worked fine for example. The next time
not - even after closing without saving and re-opening the file. Go figure!

By forcing a redraw using 'slideshowwindows(1).View.Slide#' after making the
box visible, it became available for data entry. I wish I could find a way
that doesn't depend on the slide number so I could shuffle the order of the
slides if I need to without recoding, but I suspect that's just PowerPoint
and I'll just accept it.

At least it works now. And I like doing the prototype in PowerPoint. It
really demonstrates the user experience, plus, on hidden slides, I can put my
swim lane diagram for the logic flow, and use the Speaker's notes to describe
the fields and validation for the real application. Then the development
team will get the whole package in one file.

Thanks for your help Steve!
Julie
 
J

Julibee

That looks even simpler. Thanks!

Now, I can move the slides around and shuffle the order until both our users
and our development team are happy with it. Yay!

That gives me lots of time to try to get rid of that nasty Setup button I
had to put on each slide. Why oh why isn't there a "a new slide just loaded
in the slide show window" event that could trigger the routine? You'd think
that would a pretty obvious event...
J
 
J

Julibee

Have you got a part time job as a genie in a lamp somewhere? You just made
my whole week, month and probably year!
OnSlideShowPageChange ... Bingo!

Virtual hugs and kisses...
j
 
J

Julibee

Well, maybe I was a little hasty. It's going to take a little thinking. I
was really looking for something I could use that would run ONCE when the
page changes and then stop. My redraws are also triggering the page change
of course, so instead of my expected:
I choose the value from the combo box, a text box appears, I click in it and
type.
I'm getting:
I choose the value from the combo box, a text box appears, then disappears
before I can do anything!

Going to take a little time to think this through.... Probably have to do
something kludgy like set a switch in the routine and then flip it whenver
the user does anything on the page. <sigh>

I've always found macro programming to be a little like "2 steps forward and
one back", where instead of just telling it what you want, you call these
powerful routines, then have to write a few lines that erase some of the
stuff they do that you didn't want. It's the Microsoft philosophy of doing
everything for the user - whether he/she wants it or not!

But then, I fondly remember my IBM360 Assembler course and flipping through
core dumps madly converting Hex into something legible to figure out what
strange and wonderful things I had accomplished by accident.

Cheers!
Juli
 
J

Julibee

Steve Rindsberg said:
Julibee, not Jubilee, ya myopic, astigmatic lysdexit idjit.
Notice I didn't mention anything? I'm so lysdetix myself that I can't get
my setup routines to run and I can't see why! Guess this is where I confess
to being a VBA newbie - until a week ago I had never tried working with it
before. So I don't get about half of what the reference tells me. <aircraft
zooms overhead, julibee ducks>

I've had a permanent loop that I had to use Ctrl+Alt+Del to break.
(just sloppy code - setup called redraw which ran setup which...)

I've got routines that will not run. Like:
Private Sub OnSlideShowPageChange()
Setup
End Sub
... from which I'm deducing that making the code private to the slide puts
it in a realm that the event doesn't reach.

Putting the same routine (without the private) on each page seems to run the
Setup procedure from every slide, maybe multiple times? I've been using
debug.print to try to figure out what it actually is doing and when, and
there have been some surprises.

I haven't given up yet, but I've got some heavy slogging ahead of me to sort
this out. Heck, I'll probably have to learn something about VBA instead of
just looking at examples and playing with it empirically. Where was that
nutshell book ... I just put it down....

Cheers!
Juli
 
J

Julibee

And have a look here for a kind of How To starter kit for PPT/VBA:
I read that earlier and it made an enormous difference in my understanding.
I could not have gotten as far as I did before I posted the first question
had I not read it. Your site is brilliant and your generosity astounds me!

In the meantime, I got that little bug and squashed it and it had nothing
whatever to do with VB. A logic error on my part - flipping the switch in
the wrong place

Thank <insert deity or other superstition here> that I had the good fortune
to have a Mr. F. Waudby-Smith as my high school physics teacher. He taught
essential precepts of logic in concise statements like: "Have I ever seen
this before? What did I do last time? Did it work?" and, more relevant to
this case, "if it's getting hard, you're doing it wrong".

So after a good night's sleep, I realized that I was setting my switch
values in the wrong place. I was testing my "runsetup" switch before the
setup routine (which is the right place), then setting it at the end of
Setup() to false (so it wouldn't run it again) which is precisely the wrong
place. Then I compounded the error by setting it again to true when the
submit button is pressed, just before calling the next page. It probably
would work, but it's hard to follow and I ended up mucking it up somewhere.

In actual fact, all I needed to do was fix my Redraw sub - set runsetup to
false just before calling the same page, and then set it true immediately
after.

All is well, code is running and behaving itself properly. Could not have
done it without your help Steve - even if I haven't taken all of your advice!

I'll close this thread now, since my 3 wishes have been granted, and hope
that you are around when I get myself into the next mess!
Juli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top