Syntax VB6, error "no current record"

I am writing an application in vb6 using sql server 2005. here is my current code.

Dim Sqlstring As String Dim rstCurrentTicket As Recordset Sqlstring = "Select SubmiterName, LastViewDate, Department, Description, Urgency, SubmitDate, ResolvedDate from TroubleTickets where Title ='" + Trim(TicketComboBox.Text) + "'" Set rstCurrentTicket = cnnSel.OpenRecordset(Sqlstring) NameText.Text = rstCurrentTicket!SubmiterName DeptText.Text = rstCurrentTicket!Department Me.DescriptionText = rstCurrentTicket!Description Me.UrgencyText = rstCurrentTicket!Urgency 

when I run this code, I get an error code saying:

"Runtime error: '3021'" "no current entry"

and highlights this line of code:

 NameText.Text = rstCurrentTicket!SubmiterName 

Any suggestions on how to fix this?

+4
source share
2 answers

Keith is definitely right, but I would like to give a little more detail.

For ADO and DAO, you have a Begin-of-File (BOF) marker and an end-of-file marker (EOF). Records are returned as follows

 [BOF] [Record one] <- [Record two] ... [Record n] [EOF] 

The arrow indicates where the cursor is. The cursor indicates a record in the set recordset.

If the records do not return, you get this

 [BOF] [EOF] 

So, if both boxes are checked, there are no entries. If EOF is installed, either you do not have records, or you passed the last record. (You move this cursor to the next record with this command.)

 rstCurrentTicket.MoveNext 

You can also check

 If (rstCurrentTicket.EOF and rstCurrentTicket.BOF) Then msgbox "There were no Trouble Tickets found." Else 'Do something here. End If 
+4
source

Your record set has no results. You can check it as follows:

 If Not rstCurrentTicket.EOF Then NameText.Text = rstCurrentTicket!SubmiterName DeptText.Text = rstCurrentTicket!Department Me.DescriptionText = rstCurrentTicket!Description Me.UrgencyText = rstCurrentTicket!Urgency End If 

EOF = End of file = End of record set reached.

+9
source

All Articles