Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dialog Box Error check 1

Status
Not open for further replies.

Person51

Programmer
Mar 3, 2006
16
0
0
US
Hey all,
I've got a completed program / macro, I'm now trying to throw in an error check(s). The first field in my dialog box, asks for a date in a specific format, MM-DD-YY. I have a simple text underneath the textbox that states to enter that way, but in an effort to make the code more efficient against bad user input, I'd like to have it check against a set parameter.

First, I tried using this:

Dim A as Integer
Dim dash
dash = "-"
FDate = A + A + dash + A + A + dash + A + A

Then, I put it into a simple If / Then

(Install_Date is the textbox field from the Dialog box)
If Install_Date <> Fdate Then
MsgBox" Please enter date in correct format"
GoTo Dialog:
End If

I could get it to work if the date was input as 07-0606, but it got me thinking if the user entered something absurd such as a month or day that didn't exist, it'd still accept it, short of programming an entire calendar. I looked for date formats, like CVDate but kept coming up with nothing that would work for what I'm trying to do. If anyone has any ideas or has any existing code, I'd more than appreciate the help. The other fields I'm going to error check might be easier, such as if the first / last name fields contain a numeric then to error, and if a zipcode entry is longer than 5 digits then to again error. Again, I thank any and all that respond.
- 51
 
Check out function IsDate() in your help files.

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Try
Code:
If Not IsDate(Install_Date) Then
    MsgBox"   Please enter date in correct format"
    GoTo Dialog:
End If
Should accept formats:
01/01/2006
01-01-2006
01/01/06
01-01-06

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
If the format 01-01-06 is important check out the format function
Code:
Dim Install_Date As Variant
Install_Date = "01/01/2006"

If IsDate(Install_Date) Then
    Install_Date = Format(Install_Date, "mm-dd-yy")
Else
    GoTo Dialog:
End If

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Thanks Wilson, I ended up with a slightly different version but still functional.

Dim FDate
FDate = Format(Install_Date, "mm-dd-yy")
If (Install_Date <> FDate) Then
MsgBox" Date entered in wrong format"
GoTo Input:
End If
If Not IsDate(Install_Date) Then
MsgBox" Date entered is invalid"
GoTo Input:
End If

That seems to work for my code, making it so the date has to be in correct format and it actually has to be a valid calendar type.

Working on another error check, where I have a textbox entry that is always 16 characters long, (being 3 alpha and then 13 numeric) but everything I've tried so far isn't working.
I've used Val, Right, Left, and Len. functions.
I've tried using this :
Dim Z as Integer
Z = 16
Check = Len(Order, Z)
If Order_No <> Check Then
MsgBox" Invalid Order Number."
GoTo Input:
ElseIf Order_No = "" Then
MsgBox" Enter the Order Number."
GoTo Input:
End If

Used some other variations, but with no success.
Searched through the extremely helpful "Help Topics" for a length counter, but can't find one. The VB I've wrote in before had this, however, I'm not sure if Attachmate does.
Any ideas?
 
Well, I slap myself for too much coffee this morning when the solution was right there.

Z = 16
Check = Len (Order)
If (Check <> Z) Then
MsgBox" Invalid order number"
End If

Now onto a new check.
If three textbox entries contain anything but alpha, I need an error result.
Hopefully I get this figured out so I can get some lunch.
 
TestMe = "0a1A2b"

For x = 1 to len(TestMe)
if IsNumeric(mid(TestMe,x,1)) then
msgbox mid(TestMe,x,1)+" Is Numeric"
Else
Msgbox mid(TestMe,x,1)+" Is Alpha"
End If
Next

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Why not let the user enter the date in the format of their choice?

Dim FDate
Install_Date = Format(Install_Date, "mm-dd-yy")
If Not IsDate(Install_Date) Then
MsgBox" Date entered is invalid"
GoTo Input:
Else 'format it for them
Install_Date = Format(Install_Date, "mm-dd-yy")
End If



[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Looking for string 16 chars in format NNNAAAAAAAAAA


For x = 1 to 16
if x <= 3 then 'looking for 3 numeric
If not IsNumeric(mid(TestMe,x,1)) then msgbox mid(TestMe,x,1)+" Should be Numeric"
Else 'last 13 expect non numeric
If IsNumeric(mid(TestMe,x,1)) then msgbox mid(TestMe,x,1)+" Should be Alpha"
End If
Next

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Milson, thanks for all your help.
Got everything coded on that program, and now its onto another.

I have a formatting problem for telephone entry on a dialog box for an error check.

In the box, I'm asking for a specific entry format, due to the parameters of the program, it has to be in a format of :

111 111-1111

Tried using :

Dim A as Integer
A = 0 Or 1 Or 2 Or 3 Or 4 Or 5 Or 6 Or 7 Or 8 Or 9
TNCheck = Format(TNCheck, AAA+" "+AAA+"-"+AAAA)
IF TN <> TNCheck Then
MsgBox" entered incorrectly"
End If

Also tried declaring the dash, tried using the TNCheck without any pitted format. Thought about just having the user enter the TN as 10 digits then format for them, though the formatting is incorrect from the get go. Any ideas, I'm all eyes and ears.
 
This would work if you had them input the phone number with no spaces or dashes:
Code:
If IsNumeric(TNCheck) And Len(TNCheck) = 10 Then
    TNCheck = Format(TNCheck,"@@@ @@@-@@@@")
Else
    MsgBox "Entered incorrectly"
End If

If you want something that requires that specific format then it'd require something like this:
Code:
If Len(TNCheck) <> 12 Or IsNumeric(Left(TNCheck,3)) = 0 _
  Or Mid(TNCheck,4) <> " " Or IsNumeric(Mid(TNCheck,5,3)) = 0 _
  Or Mid(TNCheck,9) <> "-" Or IsNumeric(Right(TNCheck,4)) = 0 Then
    MsgBox "Entered incorrectly"
End If
 
Code:
PhoneMsg = "Enter Phone Number as follows (8003334444)"

While Len(PhoneNum) <> 10 or Not IsNumeric(PhoneNum)
     PhoneNum = InputBox(PhoneMsg)
     PhoneMsg = "Invalid entry, use this format (8003334444)"
Wend

PhoneNum = format(PhoneNum,"@@@ @@@-@@@@")
msgbox PhoneNum

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top