ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   User form with looping doesn't start at right place. (https://www.excelbanter.com/excel-programming/353279-user-form-looping-doesnt-start-right-place.html)

Rominall

User form with looping doesn't start at right place.
 
I have a user form that runs through a list of questions. At form initialize
it runs a couple of macros one of which is a looping Public statement Loop =
loop +1 kind of (I need this to keep track of some other things). When the
user clicks a start over button (sets Loop to 0) the form doesn't start with
the same question as it does when it initializes. What's going on?

sebastienm

User form with looping doesn't start at right place.
 
Hi,
Seeing part of your code would be helpfull.

It could be that you don't unload the form before starting over which would
cause the Initialize sub not to be re-run.
When a form is displayed for the first time, the Initialize sub is run. Then
if you hide the form (Me.Hide) the form is still there but hidden; once you
do a Show again, the form shows up without running Initialize.
Instead, when hidding the form, do an unload. Next time you show it, the
Initialize sub will be run:
Private Sub cmdOK_Click()
'...
Unload Me
End Sub

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Rominall" wrote:

I have a user form that runs through a list of questions. At form initialize
it runs a couple of macros one of which is a looping Public statement Loop =
loop +1 kind of (I need this to keep track of some other things). When the
user clicks a start over button (sets Loop to 0) the form doesn't start with
the same question as it does when it initializes. What's going on?


Rominall

User form with looping doesn't start at right place.
 
I'm shortening some stuff but it should give you a good idea.
Initizialize userform application.run "Loop" & "Question"
'Question macro
'Get row based on Loop Num

RowResp = LoopNum
Range("A" + RowResp + "").Activate
Question = Activecell.value

'User form NEXTButton on click
Question.label = Question
Response.ControlSource = ("E" + RowResp +")

'User Form StartOverButton on click

LoopNum = 0

This is really the problem - when you click start over the QuestionLabel is
one row behind but the response goes to the correct row. Do I need to unload
and then reload the user form when the hit start over? Or do I need to put
the Question label in the initilize part? (I choose to put it in the button
click event because I wanted it hidden until they read a disclaimer and
clicked next - the question box is hidden until that point)

What would be the code?
I'm one of those people who knows enough to get myself in a lot of trouble
and not enough to get myself out of it.



"sebastienm" wrote:

Hi,
Seeing part of your code would be helpfull.

It could be that you don't unload the form before starting over which would
cause the Initialize sub not to be re-run.
When a form is displayed for the first time, the Initialize sub is run. Then
if you hide the form (Me.Hide) the form is still there but hidden; once you
do a Show again, the form shows up without running Initialize.
Instead, when hidding the form, do an unload. Next time you show it, the
Initialize sub will be run:
Private Sub cmdOK_Click()
'...
Unload Me
End Sub

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Rominall" wrote:

I have a user form that runs through a list of questions. At form initialize
it runs a couple of macros one of which is a looping Public statement Loop =
loop +1 kind of (I need this to keep track of some other things). When the
user clicks a start over button (sets Loop to 0) the form doesn't start with
the same question as it does when it initializes. What's going on?



All times are GMT +1. The time now is 04:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com