UserForm updating most, but not all, very inconsistent

ScottUlmer

New Member
Joined
Dec 13, 2016
Messages
29
Hey, so I have a userform which is supposed to update based off of another sheet. The user is given 5 options that update, however only 1,3,4 work while 2,5 do not. I double checked (more like 10x) the file and even copied down the lines that work into where 2 and 5 are located, but no matter what I do the userform will not update to reflect those two. I checked to make sure the options are being noticed when selected via message box (“you chose option 2”) and everything else on it should be uniform and if it works for one, work for all. I checked the links and again, the message box confirmed it is pulling in the data I want, just the userform won’t update when I choose 2 and 5. Any ideas?

Private Sub NextEvent()
If NextEventID = 0 Then
EventID = Sheets("Events").Range("G" & EventID)
End If
If NextEventID = 1 Then
EventID = Sheets("Events").Range("J" & EventID)
MsgBox ("Second option")
End If
If NextEventID = 2 Then
EventID = Sheets("Events").Range("M" & EventID)
End If
If NextEventID = 3 Then
EventID = Sheets("Events").Range("P" & EventID)
End If
If NextEventID = 1 Then
EventID = Sheets("Events").Range("S" & EventID)
End If

Me.Caption = Sheets("Book Settings").Range("B1") & " - " & Sheets("Saved Game").Range("B1") & " " & Sheets("Saved Game").Range("B2") & " - " & Sheets("Events").Range("B" & EventID) & " - " & Sheets("Events").Range("C" & EventID) & " §" & EventID
labelCurrentSelectedOption.Caption = "Please selection an option"

oldHealth = Health + Sheets("Events").Range("T" & EventID)
Health = oldHealth

oldMana = Mana + Sheets("Events").Range("U" & EventID)
Mana = oldMana

oldHunger = Hunger + Sheets("Events").Range("V" & EventID)
Hunger = oldHunger

oldGold = Hunger + Sheets("Events").Range("W" & EventID)
Gold = oldGold

PercentHealth = (Health / MaxHealth) * 100
PercentMana = (Mana / MaxMana) * 100
PercentHunger = (Hunger / MaxHunger) * 100

FormStoryTeller.labelCurrentHealthBar.Width = PercentHealth
FormStoryTeller.labelHealthPercent = "Health: " & PercentHealth & "%"

FormStoryTeller.labelCurrentManaBar.Width = PercentMana
FormStoryTeller.labelManaPercent = "Mana: " & PercentMana & "%"

FormStoryTeller.labelCurrentHungerBar.Width = PercentHunger
FormStoryTeller.labelHungerPercent = "Hunger: " & PercentHunger & "%"

imgEventArt.Picture = LoadPicture(strImageLocation & Sheets("Events").Range("X" & EventID) & ".jpg")

FormStoryTeller.tbEventText.text = Sheets("Events").Range("D" & EventID)
mpOptions.Pages(0).Caption = Sheets("Events").Range("E" & EventID)
mpOptions.Pages(1).Caption = Sheets("Events").Range("H" & EventID)
mpOptions.Pages(2).Caption = Sheets("Events").Range("K" & EventID)
mpOptions.Pages(3).Caption = Sheets("Events").Range("N" & EventID)
mpOptions.Pages(4).Caption = Sheets("Events").Range("Q" & EventID)
tbOption1.text = Sheets("Events").Range("F" & EventID)
tbOption2.text = Sheets("Events").Range("I" & EventID)
tbOption3.text = Sheets("Events").Range("L" & EventID)
tbOption4.text = Sheets("Events").Range("O" & EventID)
tbOption5.text = Sheets("Events").Range("R" & EventID)
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Slight update: so if I have it get called directed:
If NextEventID = 1 Then
EventID = Sheets("Events").Range("J" & EventID)
'REST OF THE CODE HERE
End If

Then it works, but then I would have to duplicate my code 5 times. Sure that works, but that is lazy and is not the proper way to do it, plus I would like to know why they do not work while the other 3 do.
The other odd thing is if I just have it as:
If NextEventID = 1 Then
EventID = Sheets("Events").Range("J" & EventID)
Call NextEvent
End If
It still only works for 1,3,4, and not 2,5. I have no idea why it is doing this. All of the variables work for the rest, the sheet is laid out the same, everything is getting called the same, but it has to for some reason have its own if statement when the other 3 do not.
 
Last edited:
Upvote 0
Even weirder, if I copy the full code into just the 2nd one, it works. But if I copy the full code into all of them 2 and 5 still do not work, but the other do. And 2 updates when I call it... but only health and mana, none of the other things on screen. 5 does not update anything. 1,3,4 update everything consistently.
 
Upvote 0
Why are you checking NextEventID for 0, 1, 2, 3 and then 1 again?

What is NextEventID? A control on the form? A variable set elsewhere in the code?
 
Upvote 0
1 again is a mistake... should have been 4. I must have missed that when I was copy/pasting/updating. Good catch! Thanks! NextEventID is updated when the user clicks a multipage... page.
Private Sub mpOptions_Click(ByVal Index As Long)
If Index = 0 Then
labelCurrentSelectedOption.Caption = mpOptions.Pages(0).Caption
NextEventID = 0
End If
If Index = 1 Then
labelCurrentSelectedOption.Caption = mpOptions.Pages(1).Caption
NextEventID = 1
End If
If Index = 2 Then
labelCurrentSelectedOption.Caption = mpOptions.Pages(2).Caption
NextEventID = 2
End If
If Index = 3 Then
labelCurrentSelectedOption.Caption = mpOptions.Pages(3).Caption
NextEventID = 3
End If
If Index = 4 Then
labelCurrentSelectedOption.Caption = mpOptions.Pages(4).Caption
NextEventID = 4
End If
End Sub
 
Upvote 0
Great news! When I fixed the issue you caught and updated it to be 4 it worked! I don't understand why just the health and mana bars updated and only on the second option. But you fixed it thank you so much. I always try to figure it out for about an hour before I ever post on here.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top