[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Error messages cause program not to work

Posted on 2006-05-06
Medium Priority
Last Modified: 2010-04-23

I have used the data connection wizard to connect VB.NET to my Access database - the result is a success. However when I try to add error messages like this:

If editCType.Text = "" Then
            MsgBox("Contact type cannot be blank", MsgBoxStyle.Information, "Error")
End If

the program no longer works because a second error message appears - that I did not create and this causes the program to stop.  

There is already some code in the program which appears to be designed to catch errors but I don't know how to use it correctly - it looks like this:

            'Attempt to load the dataset.
        Catch eLoad As System.Exception
            'Add your error handling code here.
            'Display error message, if any.
End Try

Any suggestions?
Question by:tuck1996
  • 2
LVL 52

Expert Comment

by:Carl Tawn
ID: 16621104
What error are you getting ?
LVL 34

Expert Comment

ID: 16621333
As carl_tawn says, we really need to know what error message you are getting and, ideally, on which line it is occurring.  But here's a couple of comments.

Yes, that bit of code you quoted is "designed to catch errors" but it only does so with the code placed between Try and Catch.  So, in the specific code you quoted it means that if, and only if, there is an error when the program tries to execute the line


that error will be "caught" and the message box will display a message about what it is.  If you want similar things to happen for errors with any other code, you will need to put that code after a Try and then put code to say what you want to happen after  a Catch and then put  an End Try.

One possible source of an unhandled error is in the last line of the code you show


It depends what objContactDetailDataSet_PositionChanged refers to, but it looks suspiciously like a sub to handle a binding manager's (probably a CurrencyManager's) PositionChanged Event.  And, if it is a call to such a sub, and the sub is in the standard form, it needs to be called with the arguments (sender As Object, e As EventArgs).

Finally, where does the code you show at the start come in your program?  I doubt this is the case with you, as your program would just have appeared to freeze rather than reporting an error, but if it were in the code handling the textbox's GotFocus Event, it would be circular.  Every time the last line of your code reset the focus to the textbox it would fire again.



Author Comment

ID: 16621343
The field 'Contact.CType' cannot contain a Null value because the Required property for this field is set to True.  Enter a value in this field.  I did resolve this at one point but then I could not get the form to write back to the database.
LVL 34

Accepted Solution

Sancler earned 2000 total points
ID: 16621396
That is happening because your program is attempting to commit the value in editCType.Text to the datatable (and/or from the datatable to the database) before your code has checked whether it has a valid value in it.  It's difficult to suggest in detail how you should change things to overcome this without knowing much more about your program's structure.  But have a look at this



Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

872 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