Click to See Complete Forum and Search --> : Can't Compile - Visual Basic


jazzyj99
08-08-2006, 10:12 AM
I'm using Visual Basic 6 and when I try to compile the following, I'm getting a
Compile Error - User-defined type not defined on Private oCN As ADODB.Connection Can anyone tell me why that is happening or how to solve this problem so I can compile the .cls file??

Thanks,

Jeff


Option Explicit

Const cmMDBFullpath = "C:\Underwriting_Forms\code\UnderWritingForms.mdb"
Const cmSrcTableName = "UserData"

Const UA_VALIDATED = 0
Const UA_INVALID_CREDENTIALS = 1
Const UA_SYSTEM_ERROR = 5

Private oCN As ADODB.Connection
Private oUsers As ADODB.Recordset
Private Function OpenConnection() As Boolean

Dim bRc As Boolean
bRc = True

On Error GoTo EH_OpenConnection

Set oCN = New ADODB.Connection
oCN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & cmMDBFullpath

Set oUsers = New ADODB.Recordset
oUsers.CursorLocation = adUseClient
oUsers.Open cmSrcTableName, oCN, adOpenStatic, adLockReadOnly, adCmdTable
Set oUsers.ActiveConnection = Nothing

EH_OpenConnection:

If Err.Number <> 0 Then
bRc = False
End If

OpenConnection = bRc

End Function

Private Sub CloseConnection()

On Error Resume Next

If oCN.State = adStateOpen Then oCN.Close

If oUsers.State = adStateOpen Then oUsers.Close

Set oUsers = Nothing
Set oCN = Nothing

End Sub

Private Sub Class_Initialize()
OpenConnection
End Sub

Private Sub Class_Terminate()
CloseConnection
End Sub

Public Function TestUser() As Integer

Dim bRc As Boolean
bRc = True

End Function

Public Function ValidateUser(vUserID As Variant, vPassword As Variant) As Integer

Dim sUserID As String
Dim sPassword As String

sUserID = LCase(CStr(vUserID))
sPassword = LCase(CStr(vPassword))
If oUsers Is Nothing Then
ValidateUser = UA_SYSTEM_ERROR
Else
oUsers.MoveFirst
oUsers.Find "UserID = '" & sUserID & "'"
If Not oUsers.EOF Then
If sPassword = CStr(oUsers.Fields("Password").Value) Then
ValidateUser = UA_VALIDATED
Else
ValidateUser = UA_INVALID_CREDENTIALS
End If
Else
ValidateUser = UA_INVALID_CREDENTIALS
End If
End If

End Function

russell
08-08-2006, 10:21 AM
You need to add a reference to ADO in the VB project.

In the VB6 Editor: Click Project, References

from the dialog scroll down to Microsoft ActiveX Data Objects 2.x library. use the highest version you have (i don't reccomend using 2.6 however -- so if that's the highest use 2.5).

Check the box next to it and click ok

jazzyj99
08-08-2006, 08:13 PM
got it working with what you said:)