+ Reply to Thread
Results 1 to 3 of 3

Close UserForm after clicking OK Button

  1. #1
    Registered User
    Join Date
    08-20-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2007
    Posts
    77

    Close UserForm after clicking OK Button

    Hi,

    I'd like my UserForm to close after the user hits the OK Button, but only if they've filled in TextBox12 which is a required date format.

    My code is below

    Many Thanks

    David

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Close UserForm after clicking OK Button

    If Len(Textbox12.value)>0 then
    If Not IsDate(TextBox12.Value) Then
    MsgBox "The initiation date you have specified is not valid", vbCritical, "Error message"
    Exit Sub
    else
    'Make Sheet1 Active
    Sheets(1).Activate

    'Determine EmptyRow
    emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

    'Export Data to worksheet

    Cells(emptyRow, 1).Value = NameTextBox.Value
    Cells(emptyRow, 2).Value = TextBox25.Value
    Cells(emptyRow, 3).Value = PhoneTextBox.Value
    Cells(emptyRow, 4).Value = ComboBox3.Value
    Cells(emptyRow, 5).Value = ComboBox4.Value
    Cells(emptyRow, 6).Value = TextBox1.Value
    Cells(emptyRow, 7).Value = TextBox26.Value
    Cells(emptyRow, 8).Value = TextBox2.Value
    Cells(emptyRow, 9).Value = TextBox3.Value
    Cells(emptyRow, 10).Value = TextBox4.Value
    Cells(emptyRow, 11).Value = TextBox5.Value
    Cells(emptyRow, 13).Value = ComboBox6.Value
    Cells(emptyRow, 15).Value = TextBox8.Value
    Cells(emptyRow, 16).Value = TextBox9.Value
    Cells(emptyRow, 17).Value = ComboBox5.Value
    Cells(emptyRow, 18).Value = TextBox11.Value
    Cells(emptyRow, 20).Value = TextBox13.Value
    Cells(emptyRow, 21).Value = TextBox14.Value
    Cells(emptyRow, 22).Value = ComboBox2.Value
    Cells(emptyRow, 23).Value = TextBox16.Value
    Cells(emptyRow, 31).Value = TextBox24.Value

    If IsDate(TextBox12.Value) Then
    Cells(emptyRow, 19).Value = DateValue(TextBox12.Value)
    Else
    Cells(emptyRow, 19).Value = "invalid"
    End If

    unload me
    End If
    end if

  3. #3
    Registered User
    Join Date
    08-20-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Close UserForm after clicking OK Button

    Works great, thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1