Access 2007-2016
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
 
Home   News   Tips   Glossary   Templates   Forums   Help   Logon   Order   Contact Us  
 

News      User Comments     History     Notify Me

1/1/2008 3:20:00 AM
Microsoft Access 320
By Richard Rost   Richard Rost on Facebook Richard Rost on Twitter Richard Rost on Google Plus Richard Rost on LinkedIn Email Richard Rost

 
Recordset basics, creating a recordset, moving around in recordsets, finding records.

Permanent Link
Course Link: Microsoft Access 320
Keywords: access
Post Reply

For access 2013 2016 and Office 365 which version Comment from Gioia Heiser @ 2/10/2018
For access 2013, 2016 and Office 365 which version DAO library should we use?


Reply from Alex Hedley:

Which versions do you have available?
Show Just This Thread        Post Reply
MoveNext Comment from Mohamed Salim @ 8/11/2016
Hello Computer Learning Zone family. I'am stuck. I have built a complete Recordset code except that when I want to Rs.Movenext, it won't keep going to the next record and the next record, and its only moves for one record then stop. How I can make it work to move to next record as I keep clicking next!However, The other methods works fine like Add,Eddit,Delete. Note that I have access 2016. Thank you.


Reply from Alex Hedley:

Linked question
Show Just This Thread        Post Reply
MoveNext Comment from Mohamed Salim @ 8/6/2016
Mr Alex, actually my comment was a follow up with my first question, which was about the recordset Rs.movenext that it wont skip records and its only skip one record as a click the button. So i replied yes it wont skip records and i use Access 2016. So is there a way to fix this issue? I just want to skip record by record as a click a button. Thanks.


Reply from Alex Hedley:

I usually have a
If NOT rs.EOF Then rs.MoveFirst

Looping

Do While Not rst.EOF
    'Work with your recordset
    rst.MoveNext
Loop

Show Just This Thread        Post Reply
MoveNext Comment from Mohamed Salim @ 8/6/2016
Yea when i click the button again, it won't keep moving to the next record and the next. Note that i use Access 2016, and i saw many people who have Access 2010 + facing the same issue. Whereas the other methods like Add,delete,update are working just fine. Thank you for your concern and looking forward for a solution.


Reply from Alex Hedley:

You could try
DoCmd.GoToRecord , , acNext
Show Just This Thread        Post Reply
MoveNext Comment from Mohamed Salim @ 8/2/2016
Hello Mr Richard. I've Been watching your lessons for 2 years now and i'am really doing great thanks to you. I'am facing a strange issue here. Everything works fine in my Database using rs, except that when I use rs.movenext it would move only one record. I really used your method exactly but it won't skip records like how it should do. Please help me out. Thanks


Reply from Alex Hedley:

So when you click the button again it doesn't keep moving to the next record and the next?
Show Just This Thread        Post Reply
Comment from Margarita Apostolova @ 1/20/2015
To Kevin:
Kevin, first I got the same error message because I put quotes around the AgeEq control. Once you remove them, the problem was fixed. Please see below.

If Not IsNull(Age) Then
        If MySQL <> "" Then
             MySQL = MySQL & " AND "
        End If
            MySQL = MySQL & "Age" & " " & "AgeEq" & " " & Age
              
    End If
Show Just This Thread        Post Reply
Comment from Richard Lanoue @ 6/22/2014
I upgraded my Access Computer and now work with access 2010....
It won't make me select MS DAO 3.6.
Do they have something that is equivalent?
Show Just This Thread        Post Reply
VB Bookmark Comment from Mark Stute @ 4/26/2014
Hi Richard, I have come across databases that use the term "Bookmark" in VB code. Do you cover the use of Bookmark in any of your lessons?


Reply from Richard Rost:

Not really. Perhaps in a future lesson.
Show Just This Thread        Post Reply
Recordset going to last record Comment from Zachary Marsett @ 6/10/2013
Richard,
For some reason my recordset is going to the last record I have saved in my table. As I change the last record in the table, sure enough that's what comes up in the FirstName box. I can't figure out how I'm messing up the syntax.  Here's the code I have saved:
Private Sub Command0_Click()
Dim db As dao.Database
Dim rs As Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("ChildT")

rs.MoveFirst
While Not rs.EOF
    FirstName = rs!FirstName
    rs.MoveNext
Wend

rs.Close
db.Close

Set db = Nothing
Set rs = Nothing

Is there something wrong right in front of me that I'm not noticing?


Reply from Richard Rost:

If you don't specify a sort order in your recordset, you cannot be guaranteed that the records will be in any particular order. If you want to FORCE them to sort in order, you need to say something like:

Set rs = db.OpenRecordset("SELECT * FROM ChildT ORDER BY ChildID")
Show Just This Thread        Post Reply
I have the same problem Comment from Mikki Swanson @ 12/5/2012
I'm using access 2010 as well and I'm showing the same error for
rs.FindNext MySQL
line.  Why is that?

Thanks so much
Show Just This Thread        Post Reply
Comment from  Sissoko @ 3/20/2012
this may help others..
Dim Db As Database
Dim rs As Recordset
Dim Rs2 As Recordset
Dim SqlStr As QueryDef

Set Db = CurrentDb
Set SqlStr = Db.CreateQueryDef("", "SELECT ItemTTemp.* " & _
" FROM ItemTTemp " & _
" WHERE ItemTTemp.OPTION=" & 1 & ";")

Set rs = SqlStr.OpenRecordset

Set Rs2 = Db.OpenRecordset("itemt", dbOpenDynaset)
Do Until rs.EOF

Rs2.AddNew
Rs2!itemref = rs!itemref
Rs2!itemname = rs!itemname
Rs2!itemprice = rs!itemprice
Show Just This Thread        Post Reply
Code Comment from Alex Hedley @ 3/17/2012
Hi Kevin
Doing a little debugging is always useful
Debug.Print or update a label/textbox on a form making it equal to MySQL to see exactly what your string is made up of, could be missing a space or something or as rich says the dropdown values
Alex
Show Just This Thread        Post Reply
here is my code thx Comment from Kevin @ 3/16/2012
Here is the entire code:

Private Sub Command18_Click()

    Dim db As Database
    Dim rs As Recordset
    Dim MySQL As String
    
    Status "---------"
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("CustomerT", dbOpenDynaset)
      
    MySQL = " "
    If Not IsNull(FirstName) Then
        MySQL = "FirstName LIKE '*" & FirstName & "*'"
    End If
    
    If Not IsNull(LastName) Then
        If MySQL <> "" Then
            MySQL = MySQL & " AND "
        End If
        MySQL = MySQL & "LastName LIKE '*" & LastName & "*'"
    End If
    
    If Not IsNull(Age) Then
        If MySQL <> "" Then
            MySQL = MySQL & " AND "
        End If
        MySQL = MySQL & "Age " & AgeEq & " " & Age
    End If
    
    If MySQL = "" Then Exit Sub
        
    Counter = 0
    rs.FindFirst MySQL

    Do While rs.NoMatch = False
        Status "FOUND: " & rs!FirstName & " " & rs!LastName & " " & rs!Age
        Counter = Counter + 1
        rs.FindNext MySQL
    Loop
    
    If Counter = 0 Then
        Status "No Match Found"
    End If
    
    Set db = Nothing
    Set rs = Nothing

End Sub

I even tried replacing the with:

MySQL = MySQL & "Age >= 20" & Age

but that didn't work either. I double checked that I created the combo box the same as the video. Does this have anything to do with the fact I am using 2010?  Why does the debug feature highlight the "rs.FindFirst MySQL" line

Thanks Rick. I love all the courses and appreciate how fast you get back to me. Happy St. Pat's day!


Reply from Richard Rost:

Your SQL looks fine... except you wouldn't want to say:

MySQL = MySQL & "Age >= 20" & Age

This should be just:

MySQL = MySQL & "Age >= 20"

No need to add on Age to the end of that again. Can you send me your database? ZIP it up and email it to amicron@gmail.com. Remove any sensitive data.
Show Just This Thread        Post Reply
here is my code thx Comment from Kevin @ 3/15/2012
For the life of me I do not see it. I have compared line for line to the video and I can't see where I am missing an = sign.

Also, when are you suppose to use a single quote vs. double quotes?


Reply from Richard Rost:

Kevin, repost your entire section of code again (the whole sub). I might have trimmed too much of it when I was answering your question before... and before I give you the WRONG answer, I want to make sure of something first. I was thinking you were missing an equals sign in the line:

MySQL = MySQL & "Age " & AgeEq & " " & Age

But I forgot that in that class I created a combo box with the different equality/inequality signs in it (=,<,>,etc.). So make sure that combo box is working correctly first. If that's not it, I need to see your code again.

Hey, it's been a few YEARS since that class came out. I can't remember every detail of every class. :)
Show Just This Thread        Post Reply
here is my code thx Comment from Kevin @ 3/15/2012
  
    If Not IsNull(LastName) Then
        If MySQL <> "" Then
            MySQL = MySQL & " AND "
        End If
        MySQL = "LastName LIKE '*" & LastName & "*'"""
    End If
    
    If Not IsNull(Age) Then
        If MySQL <> "" Then
            MySQL = MySQL & " AND "
        End If
        MySQL = MySQL & "Age " & AgeEq & " " & Age
    End If
    


Reply from Richard Rost:

I want to make you figure this one out on your own. It's one of those "so easy once you see it" moments that EVERYONE has. Get ready for a facepalm...

HINT: You're missing an equal sign.

Can you figure out where?
Show Just This Thread        Post Reply
Comment from Kevin  O'Malley @ 3/15/2012
I get a run time error 3077: Syntax error (missing operator) in expression whenever I try to use the Age feature (time: 8:05). When I debug it highlights "rs.FindNext MySQL".  It only does this if I try to search by age using the combo box. Any idea what is going wrong?


Reply from Richard Rost:

Let me see your code building the SQL statement.
Show Just This Thread        Post Reply
Comment from  JIm Gray @ 3/2/2012
Richard,
How about using an If EOF exit sub statement? I used this way back when I learned FORTRAN...


Reply from Richard Rost:

You could do it that way too. In programming, there are always 3 ways to do everything. This is the way I like to do it. Post here how YOU would write it, so everyone else could see.
Show Just This Thread        Post Reply
Comment from Scott Adkins @ 2/26/2012
Richard, I just noticed this. When you copy a text box, and then paste it, the pasted box shows up where the mouse pointer is. When I paste it, it shows up on the upper right corner. Is there a way to fix this?
Show Just This Thread        Post Reply
Comment from Alex Hedley @ 12/30/2011
Hi Scott,
You could use an after update event on the text box and just use the check for null or 0 to change the background colour:
TEXTBOXNAME.BackColor = vbRed

What do you mean hyperlink to the control?
You can use a GoToControl command:
DoCmd.GoToControl "TEXTBOXNAME"

Al
Show Just This Thread        Post Reply
Comment from Scott Adkins @ 12/29/2011
This is a cool class. With this status log, I would like to use it to do error checking on a form. What I am looking for is null or -0 values. When it checks the text box and finds a null or 0, can it highlight that entry and ... hyperlink it to the field that needs fixing?
Show Just This Thread        Post Reply
Comment from  Dana Michaels @ 11/27/2011
when I click Microsoft DAO 3.6 Object Library and try to save changes - I am presented with the error "Name conflicts with existing module, projet or object libarary.


Reply from Richard Rost:

Make sure you don't have any other DAO or ADO modules checked. If that still doesn't work, what version of Access are you working with?
Show Just This Thread        Post Reply
Comment from Salvatori Costa @ 5/15/2011
any idea why the rs.movenext doesn't work in Access 2010



Reply from Richard Rost:

It certainly should. Make sure you're using DAO and not ADO as your recordset type. Check your REFERENCES in the VBA editor.
Show Just This Thread        Post Reply
Comment from  Chris @ 3/28/2010
AC320.2 TS 4:32 - I noticed that you create the object db and rs and then you destroy it (Clean it up) backward - i.e. set rs to nothing then the same with db. I assume by this that there is a particular order of creation and tidying. It this assumption correct?


Reply from Richard Rost:

This just goes back to my C/C++ programming days.

In C/C++ you have to remember to manually clean up any variable pointers and other objects yourself, and in the correct order, otherwise you end up with craziness in your programs. Things called NULL POINTERS (pointers to nothing) can wreck havoc in your programs.

Think of object variables like plastic containers. If you declare a variable to a database object, that's a big container. If you then declare a variable to a recordset, then that's a container INSIDE a bigger container. It's dependent on the database object to exist.

Well, if you destroy the database pointer first, then the recordset pointer really doesn't reference anything useful since it's parent is gone. It's a small container floating out in space with nothing holding on to it. :)

HOWEVER, none of this really matters in VB or VBA because Visual Basic is very good at cleaning up after you. The guys who created VB realized that most people using it aren't professional programmers, so they made it so the language cleans up most things like this for you... unlike in C/C++ where you have to do all of the housekeeping yourself... it's a trade-off for more power to control variables right down to their memory address.

Anyhow... to answer your question, it's good FORM to clean up dependent variables before their parents, but it's not 100% necessary in VB. In fact, by default, whenever you exit a sub or function, VB will clean up that memory for you... but don't get used to it. Try to remember to clean up your variables on your own. It's a good habit to be in if you do ever decide to move on to "grown up" programming languages. :)
Show Just This Thread        Post Reply
Comment from Richard Rost @ 12/13/2009
If you actually want to PRINT the statustext data, then I would recommend creating a status TABLE, binding that control (the big text box) to a field in your table, and then storing it that way. Then you can print it if you want by making a report based on it.
Show Just This Thread        Post Reply
Comment from Bert Jansen @ 11/25/2009
Dear Richard, I mean if I want to print all the data in the statustext you've created like "Anne wilson 45",How can I do that?
AC320 Time index 12.43
Show Just This Thread        Post Reply
Comment from Richard Rost @ 11/25/2009
Bert, I don't understand your question. Can you please clarify? What do you mean by "report of the StatusText?"
Show Just This Thread        Post Reply
Comment from Bert Jansen @ 11/23/2009
Dear Richard,How can you make a report of the StatusText?
AC 320
Time index 12.43
Thanks.
Show Just This Thread        Post Reply
Recordset Uses Comment from Richard Rost @ 8/3/2009
Margaret, why not just GROUP the report based on each respondent, and then put the calculations in the footer of the group? You can use the =SUM(Field) or =COUNT(Field) functions in that footer to calculate your values.
Show Just This Thread        Post Reply
Recordset Uses Comment from Margaret Cattarin @ 7/31/2009
Richard,
I have a Response form for each of the households that return the survey.  The main form has the name and information that I need to fill in, such as #of persons in household, combined income, #Over 65 and #Under 18.
The Sub form has information that I can pick from drop down boxes (gender, years at address, marital status, and comments.

This is the point where I am stuck.  I would really like to generate two reports.  The first would list all of the survey responses sorted by household.

The second needs to have the counts or sums of each response (count of male, count of female, sum of persons Over 65, Rate of Return, % Moderate Income, % Low Income, Average Income, etc.).

If you can get me to that point, I think that I will be able to set the detail section of the report as not visible and then put all of the calculations in the report footer.

I tried a crosstab query, but I don't know how to use this in a report.

Any help you can give me will be very much appreciated.
Show Just This Thread        Post Reply
Recordset Uses Comment from Richard Rost @ 7/31/2009
Margaret, tell me more about what your report needs to look like. Have you tried a CROSSTAB query?
Show Just This Thread        Post Reply
Recordset Uses Comment from Margaret Cattarin @ 7/30/2009
Richard,
I have started a db for conducting a community survey.  I am having difficulty bringing the responder information, questions, responses, etc. together for a tabulated summary report.  Is this something that could be accomplished with Record Sets?

Thank You!
Show Just This Thread        Post Reply
X = A+X Comment from bryan binkerd @ 7/3/2009
thanks for the clarification. You rock.
Show Just This Thread        Post Reply
Comment from Richard Rost @ 7/2/2009
Bryan, that's just to continue with whatever previous StatusText was there before. It's like saying:

X = A + X

It takes X, adds A to the beginning, and then whatever X was there before. It's so you can keep a long listing of continuous "status" information.
Show Just This Thread        Post Reply
Comment from BRYAN binkerd @ 7/1/2009
on lesson 02, first recordset time frame 0736, I understand the StatusText = S & vbnewline but I don't understand the "& StatusText" that follows the statement.
Show Just This Thread        Post Reply

Add Your Comments or Subscribe
 
If you just want to subscribe to get email updates when the News is updated, then enter your name and email address and check the Notify Me box below. If you would optionally like to add your comments below to be posted, they are welcome.
 
  Your Name:  Required
  Your Email:  NOT Public
  Subject:
  Comments:

 

Sorry about this step. It's just to keep the spam bots away:
  Verify: What is 2+7:
  
  Notify me when the News is updated.
  Remember Me for my next comments
  
 
 
Please do not use this form for Customer Service inquiries! If you have questions about your account, shipping info, courses you've ordered, need passwords, etc. please use the Customer Service Center instead.

I value your comments. They will be displayed on this page (above). Your name will be displayed, but your email address will not be.
As always, I promise to never give away your personal information to anyone else, ever.

NOTE: If you don't leave your name and email address, DON'T expect a reply. I can't promise a personal reply to everyone who posts here. I TRY my best, but I cannot guarantee it. If you don't leave your real name and email address, I won't even bother. I usually just hit DELETE. -Richard

 

 

You may want to read these articles from the 599CD News:

3/23/2018Microsoft Access Developer 7
2/22/2018Microsoft Access Developer 6
2/22/2018Access Assistance Available
2/21/2018Putting Access Databases Online
2/18/2018Microsoft Access Developer 5
2/10/2018Microsoft Access Developer 4
2/1/2018Access Tip: Salary History
7/19/2017Access Developer 2 and 3 Released
7/19/2017Microsoft Access Developer 3
7/19/2017Microsoft Access Developer 2
 

Learn
 
Accessindex
Excelindex
Wordindex
Windowsindex
PowerPointindex
Photoshopindex
Visual Basicindex
ASPindex
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search Our Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About Us
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Gift CDs
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

Google Plus    LinkedIn

Blog RSS Feed    YouTube Channel
Richard Rost Microsoft MVP