Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2007, 06:58 AM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default I have a problem

So i'm having a problem with this one:

.
.
.
    If IsEmpty(UserForm1.TextBox1.Value) = True Then
    MsgBox ("You haven't inserted the date!")
    Exit Sub
    End If

    If IsEmpty(UserForm1.ComboBox1.Value) = True Then
    MsgBox ("You haven't inserted the code of product!")
    Exit Sub
    End If
.
.
.


I can't understand this: When UserForm1.TextBox1.Value or/and UserForm1.ComboBox1.Value is empty, it doesn't show msgbox:es at all. Why's that. There are some mistakes with the code?

Thanks for advance.

T: -Jaromir-


- Finlandoo bailando -
 
Old February 10th, 2007, 04:00 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jaromir,

Change your code like this

If UserForm1.TextBox1.Value = "" Then
    MsgBox ("You haven't inserted the date!")
    Exit Sub
End If

If UserForm1.ComboBox1.Value) = "" Then
    MsgBox ("You haven't inserted the code of product!")
    Exit Sub
End If


-vemaju
 
Old February 10th, 2007, 06:17 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Try

If Trim(UserForm1.TextBox1.Value) = "" Then
    MsgBox ("You haven't inserted the date!")
    Exit Sub
End If

If Trim(UserForm1.ComboBox1.Value)) = "" Then
    MsgBox ("You haven't inserted the code of product!")
    Exit Sub
End If

The trim should remove the spaces, hence it will be better.

If you want to improve the performance check the length

If len(Trim(UserForm1.TextBox1.Value)) = 0 Then
    MsgBox ("You haven't inserted the date!")
    Exit Sub
End If

If len(Trim(UserForm1.ComboBox1.Value))) = 0 Then
    MsgBox ("You haven't inserted the code of product!")
    Exit Sub
End If

Cheers
Shasur

http://www.vbadud.blogspot.com
 
Old February 12th, 2007, 08:12 AM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks mates. Now it works properly. Have a nice week. :)

T: -Jaromir-


- Finlandoo bailando -









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.