PC Review


Reply
Thread Tools Rate Thread

DAO Recordset Issue

 
 
TeeSee
Guest
Posts: n/a
 
      4th Mar 2010
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
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      5th Mar 2010
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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
recordset issue Joseph Atie Microsoft Access VBA Modules 5 12th Aug 2009 02:11 AM
Issue editing a recordset jonathansnyder via AccessMonster.com Microsoft Access VBA Modules 5 7th Nov 2007 11:44 PM
Re: Recordset Type Issue Dirk Goldgar Microsoft Access Forms 3 1st Sep 2004 05:46 AM
update recordset issue David Microsoft Access VBA Modules 2 25th Feb 2004 04:33 PM
update recordset issue David Microsoft Access VBA Modules 3 25th Feb 2004 07:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:42 PM.