|
-
Nov 3rd, 1999, 06:09 AM
#1
Thread Starter
Hyperactive Member
Ok, what I'm trying to do, is create an error handling routine. What I want the program to do, is check to see if any of four text boxes are empty, and if one is, then it displays the appropriate error message. Then once it is done, IF AND ONLY IF it had found any errors, then I want it to end the sub. However, I do not know how to code this. I have included the code that I have tried already, but this gives me an error message on the "End Sub" line in the If Then statement, whether the statement is true or not. Please help me figure out how I can do this. (The dsnerror, uiderror, and pwderror, are other commands run from a module)
Private Sub cmdContinue_Click()
dbname = txtdbname.Text
dsn = txtdsn.Text
uid = txtuid.Text
pwd = txtpwd.Text
If txtdbname.Text = "" Then
MsgBox ("Please enter a name for the database you wish to connect to."), , "Error: database name not entered"
dsnerror
uiderror
pwderror
End Sub
End If
If txtdsn.Text = "" Then
MsgBox ("Please enter a data source name for the database you wish to connect to."), , "Error: dsn not entered"
uiderror
pwderror
End Sub
End If
If txtuid.Text = "" Then
MsgBox ("Please enter a valid username for the database you wish to connect to."), , "Error: No username entered"
pwderror
End Sub
End If
If txtpwd.Text = "" Then
MsgBox ("Please enter a valid password for the database you wish to connect to."), , "Error: No password entered"
End Sub
End If
On Error GoTo dberror
X = "ODBC;database=" & dbname & ";DSN=" & dsn & ";UID=" & uid & ";PWD=" & pwd
Set db = OpenDatabase("", False, False, X)
dberror
MsgBox ("Some of the information you entered was invalid, please re-enter the information and make sure that it is correct."), , "Error: Invalid Information Entered"
End Sub
Load frmMain
frmStartup.Hide
frmMain.Show
Unload frmStartup
End Sub
------------------
Thanks,
Ryan
[email protected]
ICQ# 47799046
-
Nov 3rd, 1999, 06:11 AM
#2
Change the End Sub lines that you added to Exit Sub.
------------------
Marty
-
Nov 3rd, 1999, 06:23 AM
#3
Here are a few other things:
1) It will be annoying to the user of your program to correct one error and then find out he/she has a second, third and fourth error. You should probably check for all invalid conditions and then create one message that will list everything that is wrong. You can also do such things as changing label caption (or other things) forcolors to red when a particular item is in error to help the user locate it.
2) While it won't hurt anything you don't need to both Load and Show a form. As soon as you Show it, it will automatically be loaded.
3) You also don't need to both Hide and Unload a form. Either one will remove it from view. Use Hide when you want to be able to quickly redisplay it, and Unload when it won't be needed again.
4) You need an Exit Sub between Set db = OpenDatabase("", False, False, X)anddberror. Otherwise the code will "fall through" to and execute the error code even when the db call is OK.
------------------
Marty
-
Nov 3rd, 1999, 06:24 AM
#4
Thread Starter
Hyperactive Member
Thanks! Now it works fine, Thank you again.
------------------
Thanks,
Ryan
[email protected]
ICQ# 47799046
-
Nov 3rd, 1999, 06:30 AM
#5
Thread Starter
Hyperactive Member
I originally wanted to be able to create one single message that would list all applicable errors in the text boxes, but I couldn't figure out how to do that, could you give me some examples?
------------------
Thanks,
Ryan
[email protected]
ICQ# 47799046
-
Nov 3rd, 1999, 09:06 AM
#6
Hyperactive Member
dim strErrorMsg
'check for error 1
if error 1 = true then strerrormsg=strerrormsg & "#1 is bad" & vbcrlf
and just keep checking for errors and adding them on
'then display strErrorMsg
msgbox strErrorMsg
-
Nov 4th, 1999, 06:45 AM
#7
Thread Starter
Hyperactive Member
Ok, so then if I have a strerrormsg that equals "#1 is bad #2 is bad #3 is bad" then how would I convert that to an error message. I don't understand how you can get each message that is accociated with the respective error number to be displayed in a MsgBox when you have multiple errors reported. Please help. I really want to get this to work. Thanks.
------------------
Ryan
[email protected]
ICQ# 47799046
-
Nov 4th, 1999, 08:30 AM
#8
There are a lot of ways to do it. Here is one:
Code:
Dim bErrorFound As Boolean
Dim sMsg As String
sMsg = "The following data is missing or incorrect" _
& vbCrLf
If Text1.Text <> "Correct answer for Text1" Then
bErrorFound = True
sMsg = sMsg & vbCrLf & "Text1 is invalid"
End If
If Text2.Text <> "Correct answer for Text2" Then
bErrorFound = True
sMsg = sMsg & vbCrLf & "Text2 is invalid"
End If
If Text3.Text <> "Correct answer for Text3" Then
bErrorFound = True
sMsg = sMsg & vbCrLf & "Text3 is invalid"
End If
If bErrorFound Then
MsgBox sMsg, vbOKOnly, "Validation Errors"
End If
------------------
Marty
-
Nov 4th, 1999, 11:26 PM
#9
Thread Starter
Hyperactive Member
Ok, Thank you so much for all your help. I think I get the rest of the code figured out now. Thank you.
------------------
Ryan
[email protected]
ICQ# 47799046
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|