Here is my code
nothing is happen when i am clicking
or some times only one record is moved for move next
Private Sub cmdnext_Click()
Dim st As String
Dim que As String
Dim con As ADODB.Connection
Dim REC As ADODB.Recordset
st = "provider=microsoft.jet.oledb.4.0;Data source=" + App.Path + "db1.mdb"
Set con = New ADODB.Connection
With con
.ConnectionString = st
.Open
End With
que = "select * from class_add where class='" + cmbedit.Text + "'"
Set REC = New ADODB.Recordset
REC.Open que, con, adOpenDynamic, adLockReadOnly
REC.MoveNext
If Not REC.BOF Then REC.MoveNext
txtclass.Text = REC("class")
txtteacher.Text = REC("claasteacher")
txtleader.Text = REC("leader")
totstd.Text = REC("totstd")
txtsubj.Text = REC("no_subj")
txtroom.Text = REC("room_no")
End If
End Sub
thank you for spending your time
I see 2 problems with your code.
1) Each time you call cmdnext_Click, you're reopening the database. Each time you do that, you start at the beginning of the file. You need to have the database opened once, somewhere else in your program. Be sure that the record set is visible from this sub.
2) In order to use the "Next" function, you need a loop like this
'test for no records
IF REC.BOF and REC.EOF then
msgbox "No Records Found"
exit sub
end if
IF NOT REC.EOF then
REC.MoveNext
(display your fields)
END IF
Again, this will only work if your database is opened outside of the cmdNext_Click routine.
1,244 views
Usually answered in minutes!
×