etdreaming
asked on
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\tes tfile.csv" For Append As #1
Print #1, strID
Close #1
mUserName = InputBox(prompt:="Type your FIRST name only", Title:="Personalize")
ActivePresentation.SlideSh owWindow.V iew.Next
End Sub
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\tes
Print #1, strID
Close #1
mUserName = InputBox(prompt:="Type your FIRST name only", Title:="Personalize")
ActivePresentation.SlideSh
End Sub
ASKER
It doesn't like < If isnumeric(strID) = False > I get a syntax error. Any ideas?
yeah... add a "then" :>)
ASKER
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
Mike
ASKER
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent. thx much.
Mike
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!
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\tes
Print #1, strID
Close #1
mUserName = InputBox(prompt:="Type your FIRST name only", Title:="Personalize")
ActivePresentation.SlideSh
End Sub