By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Navigation buttons

P: 52
Hi, i want to do navigation button like first, previous, next and last using command button. When user click the first button, the first record in access must appear . I do using the coding below but it not going to first record , it goes to records in 288 row.

Private Sub cmdFirst_Click()

' Open a connection.
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & App.Path & "\Everspark2.mdb"
conn.CursorLocation = adUseClient
'Open the Connection
conn.Open


'Define an SQL statement (asking for all columns of the Solicitor table)
sqlString = " SELECT * FROM Alternator"

'execute the SQL statement and put the resulting set of record in recordset variable
Set rs1 = conn.Execute(sqlString)

rs1.MoveFirst
GetFields

rs1.Close
conn.Close

End Sub

Private Sub GetFields()
' Places field data into the text boxes -

txtAltId1.Text = rs1.Fields(0).Value
txtEversparkNo1.Text = rs1.Fields(1).Value
End Sub

Plz help me.Thanks in advance.
Apr 15 '08 #1
Share this Question
Share on Google+
8 Replies


debasisdas
Expert 5K+
P: 8,127
What is the problem with your code ?

1.use the move methods
2.check for BOF/EOF
3.display the field in desired control.
Apr 15 '08 #2

P: 66
try using Order by in Select statemenyt
Apr 15 '08 #3

P: 52
Thanks for the reply . I had put the orderby clause in the coding , its work fine to first and last button but it not moved to next or previous data when click the associate button.
Apr 16 '08 #4

debasisdas
Expert 5K+
P: 8,127
try to use this sample code
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFirst_Click()
  2.   On Error GoTo GoFirstError
  3.  
  4.   adoPrimaryRS.MoveFirst
  5.    Exit Sub
  6.  
  7. GoFirstError:
  8.   MsgBox Err.Description
  9. End Sub
  10.  
  11. Private Sub cmdLast_Click()
  12.   On Error GoTo GoLastError
  13.  
  14.   adoPrimaryRS.MoveLast
  15.    Exit Sub
  16.  
  17. GoLastError:
  18.   MsgBox Err.Description
  19. End Sub
  20.  
  21. Private Sub cmdNext_Click()
  22.   On Error GoTo GoNextError
  23.  
  24.   If Not adoPrimaryRS.EOF Then adoPrimaryRS.MoveNext
  25.   If adoPrimaryRS.EOF And adoPrimaryRS.RecordCount > 0 Then
  26.     Beep
  27.  
  28.     adoPrimaryRS.MoveLast
  29.   End If
  30.  
  31.   mbDataChanged = False
  32.  
  33.   Exit Sub
  34. GoNextError:
  35.   MsgBox Err.Description
  36. End Sub
  37.  
  38. Private Sub cmdPrevious_Click()
  39.   On Error GoTo GoPrevError
  40.  
  41.   If Not adoPrimaryRS.BOF Then adoPrimaryRS.MovePrevious
  42.   If adoPrimaryRS.BOF And adoPrimaryRS.RecordCount > 0 Then
  43.     Beep
  44.  
  45.     adoPrimaryRS.MoveFirst
  46.   End If
  47.  
  48.  Exit Sub
  49.  
  50. GoPrevError:
  51.   MsgBox Err.Description
  52. End Sub
  53.  
Apr 16 '08 #5

P: 52
What is mbDataChanged = False at line 31 ?
I had try the coding the error message of
Operators is not allowed when the object is closed . What does the error mean ?
Apr 17 '08 #6

debasisdas
Expert 5K+
P: 8,127
this code is part of an application. Just comment / remove that line.
Apr 17 '08 #7

P: 52
On Error GoTo GoPrevError

If Not rs1.BOF Then rs1.MovePrevious
If rs1.BOF And rs1.RecordCount > 0 Then
Beep

rs1.MoveFirst
End If

Exit Sub

GoPrevError:
MsgBox Err.Description

I had used this code. But error occured. The error is
"Operation is not allowed when the object is closed "
What does the error mean ?
Apr 17 '08 #8

debasisdas
Expert 5K+
P: 8,127
it seems you lack basic knowledge of Vb programming.

Have you opened the recordset or is the recordset open while you are tring to use the move methods.
Apr 17 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.