?
Solved

validating user input when using vba

Posted on 2007-08-09
7
Medium Priority
?
901 Views
Last Modified: 2013-11-05
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
0
Comment
Question by:etdreaming
  • 4
  • 3
7 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 19664783
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
 

Author Comment

by:etdreaming
ID: 19666028
It doesn't like < If  isnumeric(strID) = False > I get a syntax error.  Any ideas?
0
 
LVL 42

Expert Comment

by:dqmq
ID: 19666626
yeah... add a "then"  :>)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:etdreaming
ID: 19669422
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
 

Author Comment

by:etdreaming
ID: 19669720
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
 
LVL 42

Accepted Solution

by:
dqmq earned 2000 total points
ID: 19674170
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
 

Author Comment

by:etdreaming
ID: 19686976
Excellent.  thx much.
Mike
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most folk recognise that Microsoft Excel, being a numbers-and-formulae-centric application attracts programmers due to the natural fit in mindset. Conversly, when opening Microsoft's dominant presentation creative application, few consider what…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to edit the master slide. They will also learn how to combine multiple themes into one master slide to use them in their presentation.
The viewer will learn how to edit text. This includes Font, Spacing, Resizing, Color, and other special text options.
Suggested Courses

809 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