+ Reply to Thread
Results 1 to 7 of 7

Userform Error Check and Textbox Help

Hybrid View

  1. #1
    Registered User
    Join Date
    06-13-2011
    Location
    Boulder, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    61

    Userform Error Check and Textbox Help

    Hey Guys,


    I've created a program to load and manipulate text files of data. When the macro is initiated the first thing the user encoutners is my userform which contains 5 textboxes requiring the user to input integer values in the text box. The only buttons on the userform are a calculate button and a cancel button. I have already written the code for the cancel button but need some assistance witht the calculate button. Currently, pressing the calculate button hides the userform and loads a file launcher where the user can select their data file and then the macro imports the data directly into an excel worksheet. Once this is completed the userform unloads. However, at the moment the calculate button will launch the file chooser even if the 5 textboxes are empty. This is my first issue:

    What is a simple and efficient code to prevent the file chooser from launching if the textboxes are not all filled with integer values?

    Secondly,
    How can I display these textbox values in my newly generated spreadsheet?

    Here is my code for the calculate button so far:

    
    Private Sub Done_Click()
    
    Dim blnFileOpened As Boolean
    
    Initialize.Hide
    
    blnFileOpened = OpenText
    
    If blnFileOpened Then
        Call Destrezas
    End If
    
    Unload Me
    
    End Sub
    Thanks again!

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Userform Error Check and Textbox Help

    Try this
    Private Sub Done_Click()
        Dim oCtrl As MSForms.Control
        Dim blnFileOpened As Boolean
        For Each oCtrl In Me.Controls
            If TypeName(oCtrl) = "TextBox" & oCtrl = Empty Then
                MsgBox "Please complete all text boxes", vbCritical, "Input required"
                Exit Sub
            End If
        Next oCtrl
        
        Initialize.Hide
        blnFileOpened = OpenText
        If blnFileOpened Then
            Call Destrezas
        End If
        Unload Me
    End Sub
    For entering data see the DatabaseForm
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-13-2011
    Location
    Boulder, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Userform Error Check and Textbox Help

    Roy,

    Thanks for the quick response but I'm having some trouble with the code.

    If TypeName(oCtrl) = "TextBox" & oCtrl = Empty Then
    From this snippet of code For the TypeName portion should I replace this with the name of the userform or the name of the textbox? I have currently tried both and have generated run time errors in both instances.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Userform Error Check and Textbox Help

    You shouldn't need to change anything.

  5. #5
    Registered User
    Join Date
    06-13-2011
    Location
    Boulder, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Userform Error Check and Textbox Help

    When I attempt to run the code, I receive a run time error that says wrong number of arguments or invalid property assignment. Any ideas on what this could be from?

    Note:

    Also, when thinking about my code leaving the text boxes blank would be okay but I do need to ensure that the input values are integers and not text
    Last edited by Impartial Derivative; 12-01-2011 at 07:15 PM.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Userform Error Check and Textbox Help

    The problem is in your part of the code. I haven't a clue what your input is doing, my check code works fine on it's own

    Have you got a UserForm called Initialize, your code is attempting to hide that form
     Initialize.Hide
    I can't see any variable named OpenText & whether you give it a value
    Attached Files Attached Files
    Last edited by royUK; 12-02-2011 at 03:28 AM.

  7. #7
    Registered User
    Join Date
    06-13-2011
    Location
    Boulder, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Userform Error Check and Textbox Help

    Roy,


    I define OpenText with a function I had written in a different module as follows:

    Function OpenText() As Boolean
    
    Dim OpenFile As Variant
    
    MsgBox"Please select a text file",vbOKonly
    OpenFile=Application.GetOpenFilename("Textfiles (*.txt),*.txt", ,"Open a textfile...")
    
          If OpenFile <> False Then
                  
                     ' Code specific that excel import the tab delimited tab with spaces
    
          OpenText=True
          End If
    
    End Function
    This function has always seemed to work in the past but it seems to be having trouble running with the error check for the user form. Any help is greatly appreciated.

+ 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