A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

DAO Recordset Issue



 
 
Thread Tools Display Modes
  #1  
Old March 4th, 2010, 06:22 PM posted to microsoft.public.access.gettingstarted
TeeSee
external usenet poster
 
Posts: 40
Default DAO Recordset Issue

The overall objective is to sort a recordset by clicking a command
button at the top of the column. The following code is my coding
effort and I can't even get past the basics.
The strSQL creates the correct recordset (30 records) when I plug it
into the SQL query window but it returns 30 identical copies of the
first record once it gets to the rst object. Can anyone shed some
light as to what is going on. Thanks
Private Sub cmdSortYOB_Click()
Dim X As Integer
Dim strSQL As String
Dim intCount As Integer
Dim rst As DAO.Recordset
Dim rss As DAO.Recordset
strSQL = "select * from tblPersons" _
& " WHERE tblPersons.txtLastName = '" & Me.txtCboAft & "'"
Debug.Print strSQL
Set rst = CurrentDb.OpenRecordset(strSQL)
' REM rst.Sort = "[intYOB]"
' REM Set rss = rst.OpenRecordset
With rst
.MoveLast
.MoveFirst
intCount = .RecordCount
Debug.Print intCount
For X = 1 To intCount
Debug.Print X; Me.txtLastName & IntYOB
.MoveNext
Next X
End With
End Sub
  #2  
Old March 5th, 2010, 01:29 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 7,815
Default DAO Recordset Issue

Me.txtLastName indicates that you are running this on a form and you are
printing the value of the control on the form

Try the following.
With rst
.MoveLast
.MoveFirst
intCount = .RecordCount
Debug.Print intCount
For X = 1 To intCount
Debug.Print X; .Fields("txtLastName") & .Fields("IntYOB")
.MoveNext
Next X
End With

If all your are trying to do is sort a recordset, I would just add a sort to
the query string.

strSQL = "SELECT * FROM tblPersons" & _
" WHERE txtLastName ='" & me.txtCboAft & "'" & _
" ORDER BY intYOB"


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

TeeSee wrote:
The overall objective is to sort a recordset by clicking a command
button at the top of the column. The following code is my coding
effort and I can't even get past the basics.
The strSQL creates the correct recordset (30 records) when I plug it
into the SQL query window but it returns 30 identical copies of the
first record once it gets to the rst object. Can anyone shed some
light as to what is going on. Thanks
Private Sub cmdSortYOB_Click()
Dim X As Integer
Dim strSQL As String
Dim intCount As Integer
Dim rst As DAO.Recordset
Dim rss As DAO.Recordset
strSQL = "select * from tblPersons" _
& " WHERE tblPersons.txtLastName = '" & Me.txtCboAft & "'"
Debug.Print strSQL
Set rst = CurrentDb.OpenRecordset(strSQL)
' REM rst.Sort = "[intYOB]"
' REM Set rss = rst.OpenRecordset
With rst
.MoveLast
.MoveFirst
intCount = .RecordCount
Debug.Print intCount
For X = 1 To intCount
Debug.Print X; Me.txtLastName & IntYOB
.MoveNext
Next X
End With
End Sub

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:35 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.