Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 6th, 2005, 12:59 PM
smurray smurray is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 13 smurray User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 9 m 25 sec
Reputation Power: 0
Question 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

Reply With Quote
  #2  
Old April 6th, 2005, 04:00 PM
pmcnamee pmcnamee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 13 pmcnamee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 52 sec
Reputation Power: 0
You should check to see if anything is in the recordset before trying to access its fields.

if rs.eof then
'get data
...
else
'no records
end if

Reply With Quote
  #3  
Old April 11th, 2005, 09:59 AM
smurray smurray is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 13 smurray User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 9 m 25 sec
Reputation Power: 0
That worked...Thank You!

Shannon

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Getting a 'No Current Record' Error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT