You can achieve this by binding you textfiled to a data source and data field.
On click of the bottonand with rst.movenext you can get the next record apearing on your screen Try it taht way and get back to me
In the form load you should place
[Highlight=VB]
strsql = "select username from regedit "
Set rs = db.OpenRecordset(strsql)
' in the nextrecord_click you can leave the rest but have to add a line
If Not rs.EOF then /////////here,there is a mistake.message:no variable or with block variable
rs.Movenext
txtFields.Text = rs.Fields(0).Value
Else
txtFields.Text = "End of recordset
End if
' maybe you can add an extra button previous record
If Not rs.BOF then
rs.Moveprevious
txtFields.Text = rs.Fields(0).Value
Else
txtFields.Text = "Begin of recordset
For the trying , You have to dim the rs as recordset in the header of the form module.
this also applies for the db
didn't you get an error when loading the form.
Try to post all the code you have till now.
Where you dim your objects , where you fill them and where you use them.
this is all code:
Option Explicit
Const DBName As String = "\db197.mdb"
Dim strPath As String
Dim db As Database
Dim rsTitles As Recordset
Dim strsql As String
Dim blnview As Boolean
Dim rs As Recordset
Private Sub nextrecord_Click()
If Not rs.EOF Then//////////////here,there is a mistake.message:no variable or with block variable.
rs.MoveNext
txtFields.Text = rs.Fields(0).Value
End If
End Sub
Private Sub Form_Load()
'change the path!
strPath = App.Path
'open the database
Set db = OpenDatabase(strPath & DBName)
'open the recordset
Set rsTitles = db.OpenRecordset("regedit")
'make the search
strsql = "select username from regedit where not isnull(id) "
Set rs = db.OpenRecordset(strsql)
End Sub
Private Sub nextrecord_Click()
If (rs) Is Nothing Then ////////////here,there is a mistake yet.
msgBox "recordset is lost"
else
If Not rs.EOF Then
rs.MoveNext
txtFields.Text = rs.Fields(0).Value
End If
end if
End Sub
Check if you have somewhere else rs or db variable manipulation, what changes that connect what you open on form load.
Your code is workking fine on my computer
strsql = "select username from regedit "
Set rs = db.OpenRecordset(strsql)
End Sub
Private Sub Display()
txtFields.Text = rs!username
End Sub
Private Sub cmdNext_Click()
If rs.RecordCount > 0 Then
rs.MoveNext
If Not rs.EOF Then
Call Display
Else
rs.MoveLast
MsgBox "End of File.", vbInformation
Call Display
End If
End If
End Sub
[\vbcode]
flyflydream2002, I took a look at the picture you've sent.
The problem is that in the picture there are 2 code lines that are commented (the 2 green code lines). And the error you get is because you do this :
If Not Rs.EOF Then
and there is NO rs variable initialized, because you commented this line :
Set rs = ...