[RESOLVED] how to check textbox/listbox not empty-VBForums
Results 1 to 9 of 9

Thread: [RESOLVED] how to check textbox/listbox not empty

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    14

    Resolved [RESOLVED] how to check textbox/listbox not empty

    What is the syntax to check the textbox and listbox values are not empty?

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: how to check textbox/listbox not empty

    VB Code:
    1. Private Sub Command1_Click()
    2. If Text1.Text = "" Then MsgBox "textbox empty"
    3. If List1.ListCount = 0 Then MsgBox "Listbox empty"
    4. End Sub

  3. #3
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,104

    Re: how to check textbox/listbox not empty

    VB Code:
    1. 'Textbox
    2.     If Len(Text1.Text) = 0 Then
    3.        
    4.     Else
    5.    
    6.     End If
    VB Code:
    1. 'Listbox
    2.     If List1.ListCount = 0 Then
    3.    
    4.     Else
    5.    
    6.     End If
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    14

    Re: how to check textbox/listbox not empty

    No both didnt work in my case.

    I want to enable Command1 button enabled only if both text1 and text2 are not empty. I fill the 2 textboxes one after the other in the form after I run the pgm. Once I fill one text box and if I enter a single character also in the next textbox, the Command1 button shd be enabled.

    I want to enable Command2 button only if listbox is not empty.
    The same is the case with listbox also. As soon as a single list is added in the listbox, Command2 button shd be enabled.

    ----------------------------------------


    Private Sub Form_Load()

    Command1.Enabled = False
    Command2.Enabled = False
    If Text1.Text = "" And Text2.Text = "" Then
    Command1.Enabled = False
    Else
    Command1.Enabled = True
    End If
    If List1.ListCount > 0 Then
    Command2.Enabled = True
    End If

    End Sub

  5. #5
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,104

    Re: how to check textbox/listbox not empty

    Well you only stated you wanted to check the values and nothing about what you actually wanted to do.

    There are other events then you you will need to code to have the changes apply correctly. Completely different issue here.

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     Command1.Enabled = False
    4.     Command2.Enabled = False
    5.  
    6. End Sub
    7.  
    8. Private Sub Text1_Change()
    9.     If Len(Text1.Text) > 0 And Len(Text2.Text) > 0 Then
    10.         Command1.Enabled = True
    11.     Else
    12.         Command1.Enabled = False
    13.     End If
    14. End Sub
    15.  
    16. Private Sub Text2_Change()
    17.     If Len(Text1.Text) > 0 And Len(Text2.Text) > 0 Then
    18.         Command1.Enabled = True
    19.     Else
    20.         Command1.Enabled = False
    21.     End If
    22. End Sub
    No for the listbox you need to provide more info as what is the event or criteria that an item will be added? After adding it via your code just endable the Command2 button. When items are removed via your code just disable the button if there are not more items in it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  6. #6
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: how to check textbox/listbox not empty

    Rather make a control array of Text1 TextBox:
    VB Code:
    1. Private Sub Text1_Change(Index As Integer)
    2.     If Len(Text1(0).Text) > 0 And Len(Text1(1).Text) > 0 Then
    3.         Command1.Enabled = True
    4.     Else
    5.         Command1.Enabled = False
    6.     End If
    7. End Sub
    If not anything, less code

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    14

    Re: how to check textbox/listbox not empty

    Thanks RobDog888!!! Its working fine now

    Cheers

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: [RESOLVED] how to check textbox/listbox not empty

    VB Code:
    1. Private Sub Text1_Change()
    2.     Command1.Enabled = (Len(Text1.Text) > 0) And (Len(Text2.Text) > 0)
    3. End Sub
    Same for Text2
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    14

    Re: [RESOLVED] how to check textbox/listbox not empty

    I want my Command1 button to be enabled if I select any Combo1.text other than default text. I tried the following. Its not working. How shd I go abt it?
    ----------
    Private Sub Combo1_Change()
    If Combo1.Text <> "Combo1" Then
    Command1.Enabled = True
    Else
    Command1.Enabled = False
    End If
    End Sub

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.