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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No current record

Status
Not open for further replies.

precious5

Programmer
Aug 22, 2001
13
US
When I enter an invalid user id, I get the message "No current record". When I run the program in debug, the error message appears on the Seek line. It does not check for the NoMatch at this point. Once I click on the OK button for the error message, then my msgbox with error message pops up. How can I stop the No current record error message from showing? Any help would be greatly appreciated. Thanks in advance.

login:
Usr = InputBox("Enter User ID")
If Usr <> &quot;&quot; Then
datUser.Recordset.Seek &quot;=&quot;, Usr
If datUser.Recordset.NoMatch Then
MsgBox &quot;Invalid User Name, try again!&quot;, , &quot;Delete User&quot;
GoTo login
End If
End If
 
Have you tried this?

login:
Usr = InputBox(&quot;Enter User ID&quot;)
If Usr <> &quot;&quot; Then
If datUser.datUser.Recordset.Seek &quot;=&quot;, Usr
.NoMatch Then
MsgBox &quot;Invalid User Name, try again!&quot;, , &quot;Delete User&quot;
GoTo login
End If
End If
 
Hi,

What is datUser?

Anyway if you are using ADO, your .seek syntax is wrong.
Seek is used to seek on primary keys only:
recordset.Seek KeyValues, SeekOption

Where the keyvalue is an array that contains the values of the primary key that you are looking for. If your UserID is the primary key, this should work:
rs.seek array(Usr)

If UserID is not your priamry key, you could use .find:
------------------------------------------------------
LoginAgain:
Usr = inputbox (&quot;Enter User ID&quot;)
rs.find &quot;columnUser=&quot; & Usr,,1
if rs.eof then msgbox(&quot;Invalid User ID&quot;):goto LoginAgain
------------------------------------------------------

but I would do a new recordset:
------------------------------------------------------
LoginAgain:
Usr = inputbox (&quot;Enter User ID&quot;)
rs.open &quot;SELECT * FROM TblUsers WHERE ID=&quot; & Usr
if (rs.eof and rs.bof) then msgbox(&quot;Invalid User ID&quot;):goto LoginAgain
------------------------------------------------------

Sunaj
 
datUser is an DAO. I'm not using an array. UserId is the primary key. The only time the code fails, so to say, is when the user does NOT exist. It works fine when the user is in the table.
Here is all of my code:

Private Sub Form_Load()
Width = Screen.Width * 0.5
Height = Screen.Height * 0.5
Left = (Screen.Width - Width) / 2
Top = (Screen.Height - Height) / 2
sPath = &quot;H:\Ems\ems.mdb&quot;
Set db = DBEngine.OpenDatabase(sPath)
Set rs = db.OpenRecordset(&quot;Users&quot;)
Set datUser.Recordset = rs
datUser.Recordset.Index = &quot;PrimaryKey&quot;
login:
Usr = InputBox(&quot;Enter User ID&quot;)
If Usr <> &quot;&quot; Then
datUser.Recordset.Seek &quot;=&quot;, Usr
'If datUser.Recordset.Seek &quot;=&quot;, Usr .NoMatch Then
If datUser.Recordset.NoMatch Then
MsgBox &quot;Invalid User Name, try again!&quot;, , &quot;Delete User&quot;
GoTo login
End If
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top