about get next record.
for example:
Dim rs As Recordset
Private Sub nextrecord_Click()
strsql = "select username from regedit "
Set rs = db.OpenRecordset(strsql)
rs.Movenext
txtFields.Text = rs.Fields(0).Value
End Sub
Printable View
about get next record.
for example:
Dim rs As Recordset
Private Sub nextrecord_Click()
strsql = "select username from regedit "
Set rs = db.OpenRecordset(strsql)
rs.Movenext
txtFields.Text = rs.Fields(0).Value
End Sub
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
but if I do it like your speaking.
I must have a fixation's path. but I don't want to do like that.
so .......
What about next record.
You give an example , but what is it you want to achieve.
I didn't see a question about it.
Maybe you can post the answer you got through the private message in here , so people can see which answers you did get.
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
End if
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
Ill try to help you out.
It is not so good to place all your variables in the header section though.
if the recordset is lost, it could be (if your developing in access)VB 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() [COLOR=darkred] If (rs) Is Nothing Then msgBox "recordset is lost" else[/COLOR] If Not rs.EOF Then rs.MoveNext txtFields.Text = rs.Fields(0).Value End If [COLOR=darkred] end if[/COLOR] 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
that access clears the objects after exiting a sub or function.
If so you have to use a static integer to count the times that were clicked on the button.
Call if necesary
edit : (rs) Is Nothing
It works on me
but you gettin trouble if you are on last record
try correct nextrecord_Click
VB Code:
Option Explicit Const DBName As String = "\db197.mdb" Private strPath As String Private db As Database Private rsTitles As Recordset Private strsql As String Private blnview As Boolean Private rs As Recordset 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 Not rs.EOF Then rs.MoveNext Else rs.MovePrevious End If If Not rs.EOF Then txtFields.Text = rs.Fields(0).Value 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
I have an access database.
VB Code:
'make the search strsql = "select username from regedit where not isnull(id) " Set rs = db.OpenRecordset(strsql) End Sub ' Break you code here and look with watch window, what is rs.
Try to edit your form load event to this.
VB Code:
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) rs.MoveLast rs.MoveFirst MsgBox rs.RecordCount End Sub
there is a picture about that question:
Sorry man can't help you with that.
I'll start next year in first grade of basic school.
(six year old)
Swatty
Hyperactive Member
Registered: Sep 00
Location: Belgium
Posts: 457
Sorry man can't help you with that.
I'll start next year in first grade of basic school.
(six year old)
__________________
CU :-)
Swatty
I can't understand what's means??
I have tried it on my machine, working in access.
All works fine.
I can't understand what is on the jpg you've added in other reply.
That was my reply.
but it is really result like that picture.
OS:win2000,
software:VB6.
why???
Did you try this ??
VB Code:
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) rs.MoveLast rs.MoveFirst MsgBox rs.RecordCount 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
What about this...
[Highlight=VB]
Private Sub Form_Load()
Dim rs As Recordset
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]
Hope this will help...
Cheers...
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 = ...
Maybe this helped a little bit.
What about this...
VB Code:
Private Sub Form_Load() Dim rs As Recordset 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
Hope this will help...
Cheers...
wrack:thank u
thank you everyone.