Solved

Trap an errors in the ADODC control

Posted on 2004-08-13
5
311 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
  • 3
  • 2
5 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro which automatically send Excel spreadsheet to Outlook problem 2 61
Determine Range to Select 5 42
Copy a row 12 59
Can we place a tooltip on the actual vb6 form 5 35
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now