Solved

test string from textbox for alpha or numeric characters

Posted on 2014-10-07
8
142 Views
Last Modified: 2014-10-08
vba 2010

userform textbox37

what i need:

I have a variable assigned to a userform textbox
cD =  Userform2.Textbox37.text

The textbox is being filled from an  activecell.value  on the sheet

I need to check  cD to test whether or not it contains alpha or numeric characters..

I'm picking up what appears to be  " "  FROM THE Sheet cell, but cant capture what it is...so trying to determine what it is NOT ?

I have tried   ISEMPTY
VBNULLSTRING

IF cD  = " "

none of these work ?

thanks
fordraiders
0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40367158
Try
 Userform2.Textbox37.Value

instead of .Text
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40367159
Can you attach your workbook and describe the process you want to check?
0
 
LVL 3

Author Comment

by:fordraiders
ID: 40367175
If IsEmpty(UserForm2.TextBox37.value) = True Then
MsgBox "No Item To Srearch On", vbCritical, "Null Search"
End If

no good
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40367179
If Format(UserForm2.TextBox37.value) = vbNullString Then
MsgBox "No Item To Srearch On", vbCritical, "Null Search"
End If
0
 
LVL 26

Accepted Solution

by:
ProfessorJimJam earned 167 total points
ID: 40367181
here you go

create a userform and then add a text box and then click on view code of the userform and then paste this.   it will work. I tested it

Private Sub UserForm_Initialize()
    Dim ctl As Control
  Dim LC As Integer ' Loop counter
  Dim testText As String

    For Each ctl In Me.Controls
        If TypeName(ctl) = "TextBox" Then
         
   
   If Len(Me.TextBox1.Text) = 0 Then
     MsgBox "Box is empty"
     Exit Sub
   End If
   testText = Me.TextBox1.Text
   For LC = 1 To Len(testText)
     If Not IsNumeric(Mid(testText, LC, 1)) Then
       MsgBox "Entry is not entirely numeric."
       Exit Sub
     End If
   Next
   MsgBox "Entry is numeric."
        End If
    Next ctl
End Sub

Open in new window

0
 
LVL 47

Assisted Solution

by:Martin Liss
Martin Liss earned 167 total points
ID: 40367182
Try
If Trim(UserForm2.TextBox37.value) = "" Then
MsgBox "No Item To Srearch On", vbCritical, "Null Search"
End If

Open in new window

0
 
LVL 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 166 total points
ID: 40367190
Trim is the way to go:

From here:  http://microsoft.wikia.com/wiki/Microsoft_Office/VBA/General

this is a generic one
Function IsNullOrEmpty(val As Variant) As Boolean
   'First conditional validates for Nothing
   'Second condition validates for an Empty String situation "" or "     "
   Dim ret As Boolean: ret = False
   If IsMissing(val) Then
      ret = True
   ElseIf (val Is Nothing) Then
      ret = True
   ElseIf (val & vbNullString = vbNullString) Then
      ret = True
   ElseIf (Len(Trim(val)) <= 0) Then
      ret = True
   End If
 
   IsNullOrEmpty = ret
End Function

Open in new window


Usage:
if IsNullOrEmpty(UserForm2.TextBox37.value) then
MsgBox "No Item To Srearch On", vbCritical, "Null Search"
End If
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 40368423
i finally found a solution also...works fine..
http://www.techonthenet.com/excel/formulas/alphanumeric.php
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question