Consulting

Results 1 to 6 of 6

Thread: Userforms - Textbox Autofill

  1. #1
    VBAX Regular
    Joined
    May 2017
    Posts
    19
    Location

    Question Userforms - Textbox Autofill

    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
    Attached Files Attached Files
    Last edited by Auxie; 07-04-2017 at 07:32 AM.

  2. #2
    VBAX Regular
    Joined
    Jan 2011
    Posts
    35
    Location
    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

  3. #3
    VBAX Regular
    Joined
    May 2017
    Posts
    19
    Location
    Quote Originally Posted by MickG View Post
    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.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Change
    Private Sub UserForm2_Activate()
    to
    Private Sub UserForm_Activate()
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Regular
    Joined
    May 2017
    Posts
    19
    Location
    Quote Originally Posted by mdmackillop View Post
    Change
    Private Sub UserForm2_Activate()
    to
    Private Sub UserForm_Activate()
    You're a diamond. Thanks!

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •