?
Solved

Trap an errors in the ADODC control

Posted on 2004-08-13
5
Medium Priority
?
329 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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
Course of the Month8 days, 21 hours left to enroll

764 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