UserForm_Initialise not populating form

TheAbandoned

New Member
Joined
Aug 11, 2016
Messages
8
Hello Everyone, really hoping you can help here. In my workbook, i have a multi-page form that will allow the user to amend the details of the care-home they select from the drop down on the Frontpage sheet. Ultimately the 'Finish' button will write any amendments made to the numbers back to the master table. For some reason, my 'CareHome_initialise' code isn't populating the form. It was. now it isn't. but stupidly i didn't save a 'version' where it was working ok before moving on to do other things (write the code to write the amendments back to the table for example) and have tried backtracking but just end up in a mess. Now the form will open but the textboxes are empty.

I don't doubt it is something stupidly easy and i apologise if that is the case. I can't afford training for this stuff so am teaching myself as i go but i am stumped here as to why the form would populate at one point and not another...

Thanks in advance for any advice or help offered.

Code:
Option Explicit


Public Sub CareHome_Initialize()
 MultiPage1.Value = 0
    UpdateControls
    
'Page 1 Care Home name
Me.TextBox1.Value = Worksheets("Frontpage").Range("B2")


'Basics tab
Me.TextBox2.Value = Worksheets("Frontpage").Range("D5").Value
Me.TextBox3.Value = Worksheets("Frontpage").Range("D6").Value
Me.TextBox4.Value = Worksheets("Frontpage").Range("D7").Value
Me.TextBox5.Value = Worksheets("Frontpage").Range("D8").Value
Me.TextBox6.Value = Worksheets("Frontpage").Range("D9").Value
Me.TextBox7.Value = Worksheets("Frontpage").Range("D10").Value
Me.TextBox8.Value = Worksheets("Frontpage").Range("D11").Value
Me.TextBox9.Value = Worksheets("Frontpage").Range("D12").Value
Me.TextBox10.Value = Worksheets("Frontpage").Range("D13").Value
Me.TextBox11.Value = Worksheets("Frontpage").Range("D14").Value


'Medical tab
Me.TextBox12.Value = Worksheets("Frontpage").Range("D16").Value
Me.TextBox13.Value = Worksheets("Frontpage").Range("D17").Value
Me.TextBox14.Value = Worksheets("Frontpage").Range("D18").Value
Me.TextBox15.Value = Worksheets("Frontpage").Range("D19").Value
Me.TextBox16.Value = Worksheets("Frontpage").Range("D20").Value
Me.TextBox17.Value = Worksheets("Frontpage").Range("D21").Value




'People
Me.TextBox18.Value = Worksheets("Frontpage").Range("D22").Value
Me.TextBox18.Value = Worksheets("Frontpage").Range("D24").Value
Me.TextBox20.Value = Worksheets("Frontpage").Range("D25").Value
Me.TextBox21.Value = Worksheets("Frontpage").Range("D26").Value


'Deaths
Me.TextBox22.Value = Worksheets("Frontpage").Range("D28").Value
Me.TextBox23.Value = Worksheets("Frontpage").Range("D29").Value
Me.TextBox24.Value = Worksheets("Frontpage").Range("D30").Value
Me.TextBox25.Value = Worksheets("Frontpage").Range("D31").Value


'Advance care plans
Me.TextBox26.Value = Worksheets("Frontpage").Range("D33").Value
Me.TextBox27.Value = Worksheets("Frontpage").Range("D34").Value
Me.TextBox28.Value = Worksheets("Frontpage").Range("D35").Value
Me.TextBox29.Value = Worksheets("Frontpage").Range("D36").Value


'Personal
Me.TextBox30.Value = Worksheets("Frontpage").Range("H5").Value
Me.TextBox31.Value = Worksheets("Frontpage").Range("H6").Value
Me.TextBox32.Value = Worksheets("Frontpage").Range("H7").Value
Me.TextBox33.Value = Worksheets("Frontpage").Range("H8").Value
Me.TextBox34.Value = Worksheets("Frontpage").Range("H9").Value
Me.TextBox35.Value = Worksheets("Frontpage").Range("H10").Value
Me.TextBox36.Value = Worksheets("Frontpage").Range("H11").Value


'Staff
Me.TextBox37.Value = Worksheets("Frontpage").Range("H13").Value
Me.TextBox38.Value = Worksheets("Frontpage").Range("H14").Value
Me.ComboBox1.Value = Worksheets("Frontpage").Range("H15").Value
Me.TextBox39.Value = Worksheets("Frontpate").Range("H16").Value
     'General
Me.TextBox40.Value = Worksheets("Frontpage").Range("H18").Value
Me.TextBox41.Value = Worksheets("Frontpage").Range("H19").Value
Me.TextBox42.Value = Worksheets("Frontpage").Range("H20").Value
Me.TextBox43.Value = Worksheets("Frontpage").Range("H21").Value
Me.TextBox44.Value = Worksheets("Frontpage").Range("H22").Value


End Sub


Private Sub CommandButton1_Click()
    Dim Msg As String
    Dim Ans As Integer
    Msg = "Are you sure you want to cancel?"
    Ans = MsgBox(Msg, vbQuestion + vbYesNo)
    If Ans = vbYes Then Unload Me
End Sub
Private Sub BackButton_Click()
    MultiPage1.Value = MultiPage1.Value - 1
    UpdateControls
End Sub


Private Sub FinishButton_Click()
Unload CareHome
End Sub


Private Sub NextButton_Click()
    MultiPage1.Value = MultiPage1.Value + 1
    UpdateControls
    End Sub
Sub UpdateControls()
    Select Case MultiPage1.Value
    Case 0
        BackButton.Enabled = False
        NextButton.Enabled = True
    Case MultiPage1.Pages.Count - 1
        BackButton.Enabled = True
        NextButton.Enabled = False
    Case Else
        BackButton.Enabled = True
        NextButton.Enabled = True
    End Select
   
End Sub
Regards,

Rob
 
Last edited by a moderator:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi,
Change this

Code:
Public Sub CareHome_Initialize()

back to this

Code:
Private Sub UserForm_Initialize()

Regardless of your forms name this event is ALWAYS Private Sub UserForm_Initialize()

Dave
 
Last edited:
Upvote 0
Hi Dave, i have changed that but am still getting an error.

My forms name is CareHome as i have more than 1 form in the workbook. This makes it easier to identify than UserForm1, UserForm2 etc.
However If i change the name of the form back to UserForm2 and adjust the code for the command button

The command button code is:

Private Sub CommandButton1_Click()
UserForm2.Show
End Sub
and then change the first line to Private Sub UserForm2_Initialize()

This will load the form but it won't populate.

Is the root of the problem my changing the name of the form? To test i made a very quick form with 3 pages, two textbox on each picking up information from the frontpage worksheet and it works fine... the only difference being that i haven't changed the form name.

Rob
 
Upvote 0
and then change the first line to Private Sub UserForm2_Initialize()

This will load the form but it won't populate.

Rob

to repeat what I said - Regardless of your forms name this event is ALWAYS Private Sub UserForm_Initialize()

DO NOT rename the event - It must ALWAYS be UserForm_Initialize

Dave
 
Upvote 0
Ok, thank you for the response Dave, i still can't get the form to populate though. I am going back to square one and build the form from scratch in a new workbook without renaming anything. all part of the learning process. Annoying thing is that my quick form works fine.

Regards,

Rob
 
Upvote 0
Hi Dave, apologies, but i never got back to you to say thank you for your help. I rebuilt the workbook in the end as i was getting very muddled with what i had and now, without re-naming anything and using UserForm_Initialise, my project is running perfectly.

Thank you for your input, it was much appreciated.

Rob
 
Upvote 0

Forum statistics

Threads
1,214,409
Messages
6,119,339
Members
448,888
Latest member
Arle8907

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