validating user input when using vba

Below is the code I'm using in powerpoint but I'm trying to self teach myself vba and I'm a little stuck here.  This code runs just fine but what I want to do is validate the 6 digit id number and the user name.  I don't want the message box to export the data to my csv file if he enters more or less than 6 digits or if he enters text.  I want it to simply pop up over and over again until he enters exactly 6 digits.  Same thing with the message box asking for his first name.  If he enters numbers instead of text I don't want it to record the data unless he enters text.  I want that one to also pop up over and over until he enters text.  I know it can be done but I'm clueless as to how.  thx!!
Mike

Public Sub Driverid()
' after driver inputs his id# it will export it to a csv file
Dim strID As String ' this can be local if you don't use it anwher else!
strID = InputBox(prompt:="Please enter your 6 digit driver ID#", _
          Title:="Welcome to Excellence through Education!")
Open "C:\Documents and Settings\mikee\Desktop\testfile.csv" For Append As #1
Print #1, strID
Close #1
mUserName = InputBox(prompt:="Type your FIRST name only", Title:="Personalize")
ActivePresentation.SlideShowWindow.View.Next
End Sub
etdreamingAsked:
Who is Participating?
 
dqmqConnect With a Mentor Commented:
The second part goes in the place of this line:
   mUserName = InputBox(prompt:="Type your FIRST name only", Title:="Personalize")

Something like:

strID = ""
strPrompt = ""
Do while strID = ""
  strPrompt = strPrompt & "Type your FIRST name only"
  strID = InputBox(prompt:=strPrompt, _
          Title:="Personalize")
  strPrompt = ""

  If  isnumeric(strID) = True
        strID = ""   'ask again
       strPrompt = strPrompt & "Numbers are not allowed" & vbNewLine
  end if

'add any other edits here
Loop


0
 
dqmqCommented:
Here's one way--for the first part at least.  I'm betting you can't figure out the second part:


Public Sub Driverid()
' after driver inputs his id# it will export it to a csv file
Dim strID As String ' this can be local if you don't use it anwher else!
dim strPrompt as string
strID = ""
strPrompt = ""
Do while strID = ""
  strPrompt = strPrompt & "Please enter your 6 digit driver ID#"
  strID = InputBox(prompt:=strPrompt, _
          Title:="Welcome to Excellence through Education!")
  strPrompt = ""
  If len(strID) <> 6 then
       strID = ""   'ask again
       strPrompt = strPrompt & "At least 6 digits are required" & vbNewLine
  end if
  If  isnumeric(strID) = False
        strID = ""   'ask again
       strPrompt = strPrompt & "Only numbers are allowed" & vbNewLine
  end if
Loop

Open "C:\Documents and Settings\mikee\Desktop\testfile.csv" For Append As #1
Print #1, strID
Close #1
mUserName = InputBox(prompt:="Type your FIRST name only", Title:="Personalize")
ActivePresentation.SlideShowWindow.View.Next
End Sub
0
 
etdreamingAuthor Commented:
It doesn't like < If  isnumeric(strID) = False > I get a syntax error.  Any ideas?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
dqmqCommented:
yeah... add a "then"  :>)
0
 
etdreamingAuthor Commented:
I appreciate you hanging in there with me but as I mentioned I'm learning vba as I go....I've tried adding "then" in about every spot I can and to no avail.  You'll have to type out exactly how the line should look because I'm not having any luck.  Also, any ideas on the last part of the original question about forcing the user to use text when entering their name?  thx.
Mike
0
 
etdreamingAuthor Commented:
Scratch that.........I just figured out where to put the, "then".  First part is working great.  Just need some help on the final part dealing with the name.  thx!
0
 
etdreamingAuthor Commented:
Excellent.  thx much.
Mike
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.