PDA

View Full Version : [SOLVED] Userforms - Textbox Autofill



Auxie
07-04-2017, 03:20 AM
Hi all,

I've created a userform in the attached document, that works once i've hit "add" twice - can anyone suggest why it's not auto populating on the userform2.show?

Thanks in advance

MickG
07-04-2017, 03:34 AM
Try "Userform_Initialize"


Private Sub UserForm_Initialize()
Dim x
x = Format(Cells(Rows.Count, 1).End(xlUp).Row - 2, "00")
Transmittal2.Value = "704-DT-0" & x
DateBox2.Value = Format(Date, "dd/mm/yyy")
Originator.Value = "name"
Optionbutton1.Value = True
Sender.Value = "Name"
Description2.Value = ""
Media2.Value = "Email"
Copies2.Value = "1"
Description2.SetFocus

End Sub

Auxie
07-04-2017, 04:04 AM
Try "Userform_Initialize"


Private Sub UserForm_Initialize()
Dim x
x = Format(Cells(Rows.Count, 1).End(xlUp).Row - 2, "00")
Transmittal2.Value = "704-DT-0" & x
DateBox2.Value = Format(Date, "dd/mm/yyy")
Originator.Value = "name"
Optionbutton1.Value = True
Sender.Value = "Name"
Description2.Value = ""
Media2.Value = "Email"
Copies2.Value = "1"
Description2.SetFocus

End Sub




This doesn't work - I also forgot to add that I've multiple another userform in my master file hence the use of UserForm2 -

I was thinking that its perhaps that I have the other userform loaded but when I've also tried to unload that userform before this one runs, i still get the same result. Its not earth shattering but I would prefer it to auto generate.

mdmackillop
07-04-2017, 05:12 AM
Change
Private Sub UserForm2_Activate()
to
Private Sub UserForm_Activate()

Auxie
07-04-2017, 07:31 AM
Change
Private Sub UserForm2_Activate()
to
Private Sub UserForm_Activate()

You're a diamond. Thanks!

mdmackillop
07-04-2017, 09:47 AM
Stepping through the code starting with Userform.Show shows that the Activate macro was not called. For event codes, always use the macro names generated from the Drop-Downs.