Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trap an errors in the ADODC control

Posted on 2004-08-13
5
Medium Priority
?
331 Views
Last Modified: 2008-02-01
Using ADODC control to connect to SQL Server 2000....

I have a login form that takes the username and password from the user and then constructs a connection string, then connect to database and populates a datagrid if the username and password is right.

How do I trap an error that is given when the wrong username or password is put into the connectionstring?  Right now if I type in the wrong password or username it puts up a small messagebox.  The messagebox is titled "ADODC1"  the message is "Login failed for user 'ASD'"

ASD is just a bogus username...  
0
Comment
Question by:strongd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 11796903
Hello again :o)

You can use the Error event of the ADO control to catch the error and prevent the default error dialog.

Something like:

Private Sub Adodc1_Error(ByVal ErrorNumber As Long, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, fCancelDisplay As Boolean)
   
    '// 3661 is 'login failed'
    If ErrorNumber = 3661 Then
        MsgBox "Username or password incorrect"
        fCancelDisplay = True
    End If
   
End Sub

Private Sub Command1_Click()

      On Error Resume Next     '<--- We need this because if the login fails the Refresh method will cause an error

      Adodc1.ConnectionString = "blah blah blah"
      Adodc1.Refresh

End Sub


Hope this helps.
0
 

Author Comment

by:strongd
ID: 11796947
Carl, you're on a role..  You just helped me again... Thanks for everything...  This worked perfectly...

And you keep your title as "The Best!!!'

Thanks again...

0
 

Author Comment

by:strongd
ID: 11796983
Carl, can you recommend a good book that will explain the ADO objects?

I have about 5 years of VB, but I moved to a different job and started doing Oracle stuff (PL/SQL) and this is the first time I have done any VB in a few years.  I am rusty.  

In my past VB prgramming days, I didn't do any database stuff with VB.  So ADO stuff is all new for me.  

0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 11797090
Well, depending on how your feeling. Trawling MSDN will probably give you a good idea of the architecture and relationships between the different objects. Also the object browser in VB (press F2) will list all the objects, their properties/methods/events (although they can be a little vague).

Personally I like the Sams series of books (very straight forward, lots of sample code and explanations), Wrox are good too, although finding them is a bit trickier than it was after they went bust.

Also this site: http://www.w3schools.com/ado/default.asp  has a good range of tutorials. There nothing too in-depth but they'll at least give you a reasonable start.
0
 

Author Comment

by:strongd
ID: 11797114
Ahh...ok thanks..

I am familar with w3schools.com.  I have used it before in the past.  I didn't think of looking there.

Thanks again.

Have a great weekend.

0

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

618 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