Solved

test string from textbox for alpha or numeric characters

Posted on 2014-10-07
8
134 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 40

Expert Comment

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

instead of .Text
0
 
LVL 46

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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 25

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 46

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

929 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now