Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA problem with Access 2000

Status
Not open for further replies.

ScottTN

IS-IT--Management
Sep 19, 2002
22
US
I am trying to use to following code to check 2 txt fields against a table. (Security Manager) I keep getting and error 424 object required. Any Ideas?

Thanks!
***********************************************************

Private Sub cmdCheckit_Click()
On Error GoTo ConnectionError

Dim db As Database
Dim rsLogin As Recordset
Dim stDocName As String
Dim stLinkCriteria As String
Dim stMgoto As String
Dim stAppName As String


Set db = DBEngine.OpenDatabase("C:\Track.mdb")

On Error GoTo otherError
If Not db Is Nothing Then

MsgBox "HI", vbCritical, "Login Error"

Set rsLogin = db.OpenRecordset( _
"SELECT * FROM tblLogon WHERE Username = '" & frmLogin.txtUsername & "' AND Password = '" & frmLogin.txtPassword & "'", dbOpenSnapshot)


If rsLogin.EOF Then
MsgBox "Incorrect User Name or Password!", vbCritical, "Login Error"

frmLogin.txtPassword = ""
stMgoto = "mGotoUsername"
DoCmd.RunMacro stMgoto

Else
stDocName = "frmMain"
DoCmd.OpenForm stDocName, , , stLinkCriteria

End If
rsLogin.Close
db.Close
Else
MsgBox "Error Connecting To the database" & vbCrLf & "Please Contact Customer Support"
End If
Exit Sub

ConnectionError:
MsgBox "Error Connecting To the database" & vbCrLf & "Please Contact Customer Support", vbCritical
Exit Sub

otherError:
MsgBox "Error Number " & Err.Number & vbCrLf & Err.Description
Exit Sub


End Sub
 
I am not for sure. I know that it ia making it to my test message "Hi". After the message displays, I get the error. I think it is when it is setting the record set.

Scott
 
Scott,

Add a breakpoint after the msgbox and step through the code one line at a time to discover exactly the line the error is coming from.

gkprogrammer
 
If you are using Access 2000 or above, this error is usually associated with Access getting mixed up between the 2 different data object libraries DAO and ADO. Since you are using the DAO open recordset make sure you have a reference checked to one of the DAO libraries and explicitly define your data objects.

Dim db As DAO.Database
Dim rsLogin As DAO.Recordset
 
Thanks for the breakpoint and DAO tip. I was trying to say formname.fieldname instead of Me.field name.

It's working. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top