Results 1 to 2 of 2

find error in my Validate-function (that validates a textbox)

Threaded View

  1. #1
    Registered User
    Join Date
    11-10-2007
    Location
    Sweden
    Posts
    32

    find error in my Validate-function (that validates a textbox)

    Hello

    I'm a newbie with VBA who needs your help.
    I have created a userform that has several textboxs within it and an OK-button.

    In the OK-button I have the following code:
    Private Sub cmdOK_Click()
    If ValidateData = True Then
        SaveDataToWorksheet
        ClearForm
        Me.Hide
    End If
    End Sub
    The problem I'm having is with the Validate-function, see code below:
    Public Function ValidateData() As Boolean
    If txtProductName.Value = "" Then
        MsgBox "Please enter a product name."
        ValidateData = False
        Exit Function
    End If
    
    ValidateData = True
    End Function
    I have only pasted 1 If in the validate function here since the problem is the same for them all, and that is that even if the textbox txtProductName containing for example "Coca Cola", I still get the msgbox "please enter a product name".

    What am I doing wrong? I seems to me that the variable ValidateData never get True but I do not understand why.

    Thank you for your help, and a great forum.
    Last edited by VBA Noob; 11-10-2007 at 09:28 AM.

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