+ Reply to Thread
Results 1 to 3 of 3

Simple User form initialize and close

  1. #1
    Registered User
    Join Date
    04-01-2013
    Location
    KY
    MS-Off Ver
    Excel 2013
    Posts
    9

    Simple User form initialize and close

    I am doing VBA coding for the first time as of yesterday. I having some issues. I am wanting to add a user form that opens when the workbook is opened and prompts the user to input a date and then selects something from a drop down list. When they have done this and click "okay" i want the date to be checked to ensure it is in the proper format. If it is not i want it to re-prompt the user with a notification of their error without populating any fields. If the date field is in the correct format however i want the date and the selected text from the drop down to populate into two cells on the sheet. Following successful population of those fields i want the user form to close automatically. The code i have so far doesn't work. If the user inputs anything but a date into the date field it goes into an infinite failure that doesn't allow the user to reenter a date to correct the issue. I end up having to close excel with the command prompt.

    Please help!

    Private Sub CommandButton1_Click()

    Dim dateString As String, TheDate As Date
    Dim valid As Boolean: valid = True

    Do
    dateString = TextBox1.Text

    If IsDate(dateString) Then
    TheDate = DateValue(dateString)
    valid = True
    Worksheets("Time Sheet").Range("G3").Value = ComboBox1.Text
    Worksheets("Time Sheet").Range("X3").Value = TextBox1.Text
    Else

    MsgBox "Invalid date"
    valid = False
    End If
    If valid = True Then
    Me.Hide

    Loop Until valid = True
    End If

    End Sub


    Private Sub UserForm_Initialize()
    With ComboBox1
    Me.ComboBox1.List = Worksheets("Sheet1").Range("A1:A10").Value
    End With

    End Sub

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Simple User form initialize and close

    Try

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-01-2013
    Location
    KY
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Simple User form initialize and close

    That works perfectly. My issue now is that i can close the userform without populating the user field. How should i verify that the user has made a selection from the drop down before closing the form?

    I have tried to add some if then check statements but i think i am going the wrong route it seems like it should be so much easier than i am making it.

    Thank you,

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. User form on initialize to recall last entry from Excel Sheet
    By maip.kewa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-04-2014, 07:16 PM
  2. [SOLVED] Calling User form Initialize: A way to display certain tab based on which sub called?
    By emilyloz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2013, 10:06 AM
  3. Calling a user form initialize sub when entering the form to populate combobox...
    By regupnorth in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-02-2012, 07:24 AM
  4. [SOLVED] User Form Initialize Event Issues
    By Randy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-04-2005, 07:30 AM
  5. Closing user form in Initialize macro?
    By Don Wiss in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-20-2005, 04:06 AM

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