Navigation buttons
-
Hi Everybody! I am using VB6.0 & SQL Server 7.0 Following is my database Connection code Dim db As ADODB.Connection Dim rs As ADODB.Recordset Dim sql As String Set db = New ADODB.Connection db.Provider = "SQLOLEDB" db.ConnectionString = "server=SUNANDA;uid=sa;pwd=ranjita1;database=crm" db.Open Set rs = New ADODB.Recordset sql = "Select * from AccountHead" Set rs.ActiveConnection = db rs.CursorLocation = adUseClient rs.CursorType = adOpenStatic rs.LockType = adLockOptimistic rs.Open sql, , , , adCmdText I have placed navigation buttons on my form, but the Next & Previous buttons are not working properly. When I first time clicks the Next button , the recordset goes to the next record but when I click it second time, the record doesn’t get changed. When I press the previous button, the recordset points to the first record, instead of pointing to the previous record. Here is my code for navigational buttons:^): Public Sub MoveFields() txtAcId.Text = rs("AcHeadID") txtAcName.Text = rs("AcHeadName") txtAcMobile.Text = rs("Mobile") txtAcEmail.Text = rs("EmailID") End Sub Private Sub cmdFirst_Click() rs.MoveFirst MoveFields cmdPrev.Enabled = False cmdNext.Enabled = True End Sub Private Sub cmdLast_Click() rs.MoveLast MoveFields cmdNext.Enabled = False cmdPrev.Enabled = True End Sub Private Sub cmdNext_Click() rs.MoveNext If rs.EOF Then rs.MoveLast cmdNext.Enabled = False End If MoveFields cmdPrev.Enabled = True End Sub Private Sub cmdRemove_Click() rs.Delete rs.MoveNext If rs.EOF Then rs.MoveLast End If End Sub Private Sub cmdPrev_Click() rs.MovePrevious If rs.BOF Then rs.MoveFirst cmdPrev.Enabled = False End If MoveFields cmdNext.Enabled = True End Sub Pls. tell me, where I am wrong. Thanks
-
Hi Everybody! I am using VB6.0 & SQL Server 7.0 Following is my database Connection code Dim db As ADODB.Connection Dim rs As ADODB.Recordset Dim sql As String Set db = New ADODB.Connection db.Provider = "SQLOLEDB" db.ConnectionString = "server=SUNANDA;uid=sa;pwd=ranjita1;database=crm" db.Open Set rs = New ADODB.Recordset sql = "Select * from AccountHead" Set rs.ActiveConnection = db rs.CursorLocation = adUseClient rs.CursorType = adOpenStatic rs.LockType = adLockOptimistic rs.Open sql, , , , adCmdText I have placed navigation buttons on my form, but the Next & Previous buttons are not working properly. When I first time clicks the Next button , the recordset goes to the next record but when I click it second time, the record doesn’t get changed. When I press the previous button, the recordset points to the first record, instead of pointing to the previous record. Here is my code for navigational buttons:^): Public Sub MoveFields() txtAcId.Text = rs("AcHeadID") txtAcName.Text = rs("AcHeadName") txtAcMobile.Text = rs("Mobile") txtAcEmail.Text = rs("EmailID") End Sub Private Sub cmdFirst_Click() rs.MoveFirst MoveFields cmdPrev.Enabled = False cmdNext.Enabled = True End Sub Private Sub cmdLast_Click() rs.MoveLast MoveFields cmdNext.Enabled = False cmdPrev.Enabled = True End Sub Private Sub cmdNext_Click() rs.MoveNext If rs.EOF Then rs.MoveLast cmdNext.Enabled = False End If MoveFields cmdPrev.Enabled = True End Sub Private Sub cmdRemove_Click() rs.Delete rs.MoveNext If rs.EOF Then rs.MoveLast End If End Sub Private Sub cmdPrev_Click() rs.MovePrevious If rs.BOF Then rs.MoveFirst cmdPrev.Enabled = False End If MoveFields cmdNext.Enabled = True End Sub Pls. tell me, where I am wrong. Thanks
Hi Dear Please first check where you write the code for recordset and connection. Then try following code for your record movement **Next record **if not rs.eof then rs.movenext() .... end if **previous record **if not rs.bof then rs.moveprevious() ..... end if If the problem is there then please post new message with you complete form code so I can sort your issue. Regards :)
Tushar kothari********
-
Hi Dear Please first check where you write the code for recordset and connection. Then try following code for your record movement **Next record **if not rs.eof then rs.movenext() .... end if **previous record **if not rs.bof then rs.moveprevious() ..... end if If the problem is there then please post new message with you complete form code so I can sort your issue. Regards :)
Tushar kothari********
I have written the code for recordset and connection in sub main() I am calling the procedure in each click event.