
April 6th, 2005, 12:59 PM
|
|
Registered User
|
|
Join Date: Jan 2005
Posts: 13
Time spent in forums: 2 h 9 m 25 sec
Reputation Power: 0
|
|
Getting a 'No Record Found' error
In Access 2000, I am trying to create a login form where the user logs in and depending on what rights they have, another form opens. There are two tables I am using (tblGroup and tblUser)...the SQL statement uses an inner join between the tables and searches for the UserName in the User table and the Description in the Group table. If the UserName exists in the user table and the description in the Group table is 'Admin' then frmAddRecord opens...if the UserName exists in the user table and the description is 'User' in the group table, then frmSearch is opened. I want an error to be thrown if txtUserName is left blank or if the name entered is not in tblUser. With the code I have, I am receiving a 'Run-time error '3021': No Current Record.' error on this line - strUserName = rs!UserName. Does anyone know what I need to do in order for this to work properly? Any help would be greatly appreciated. Here's my code for the command button that the user hits after they enter their username:
Code:
Private Sub cmdLogin_Click()
Dim db As Database
'Dim rs As Recordset
'Dim rs As Recordset
Dim rs As Recordset
'Dim strCriteria As String
Dim strSQL As String
Dim strUserName As String
Dim strDescription As String
Dim stDocName As String
Dim stDocName2 As String
'Set rst = CurrentDb.OpenRecordset("tblUsers", dbOpenDynaset)
'Me!txtUserName = UCase(Me!txtUserName)
'criteria = "[UserName] = '" & Me!txtUserName & "'"
Set db = CurrentDb
strSQL = "Select tblGroup.Description, tblUser.UserName From tblGroup, tblUser Where tblGroup.GroupID = tblUser.GroupID and UserName = '" & txtUserName.Value & "'"
'MsgBox strSQL
'Debug.Print strSQL
Set rs = db.OpenRecordset(strSQL)
strUserName = rs!UserName
strDescription = rs!Description
stDocName = "frmAddRequest"
stDocName2 = "frmSearch"
If UCase(txtUserName.Value) = strUserName And strDescription = "Admin" Then 'Check if user is Admin
DoCmd.OpenForm stDocName, acNormal
ElseIf UCase(txtUserName.Value) = strUserName And strDescription = "User" Then 'Check if user is User
DoCmd.OpenForm stDocName2, acNormal
Else 'Not a Valid User
If Not IsNull(Me.txtUserName) Then
MsgBox "Not a valid user"
Me!txtUserName.SetFocus
End If
End If
db.Close
Set db = Nothing
Set rs = Nothing
End Sub
Thanks,
Shannon
|