473,382 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

code to move to next record

111 100+
ok i have the following snippet of code. All i want it to do is move to the next record, but i keep getting an error of: You cannot go to the specified record.

Expand|Select|Wrap|Line Numbers
  1. amount = DCount("*", "[Sheet1]")
  2. counter = 0
  3. Debug.Print amount
  4.  
  5. Do
  6. emailgroup = Me![email]
  7. DoCmd.GoToRecord , , acNext
  8. emailgroup = emailgroup & ";" & Me![email]
  9. counter = counter + 1
  10. Loop Until counter = amount
  11. Debug.Print emailgroup

how do i tell my loop to go the next record?
Sep 26 '07 #1
6 35540
cyberdwarf
218 Expert 100+
Maybe you are reading past the last record???

DoCmd.GotoRecord will move through the records by displaying them on screen. You might want to think about looping through an ADO recordset and processing each record that way.

HTH

Steve
Sep 26 '07 #2
Neekos
111 100+
thanks steve - i went with the recordset and here's where im at:

Expand|Select|Wrap|Line Numbers
  1. Set recordset = New ADODB.recordset
  2. recordset.Open "sheet1", CurrentProject.Connection
  3. recordset.MoveFirst
  4.  
  5. amount = DCount("*", "[Sheet1]")
  6. counter = 0
  7. Debug.Print amount
  8.  
  9. Do
  10. emailgroup = Me![email]
  11. recordset.MoveNext
  12. emailgroup = emailgroup & ";" & Me![email]
  13. counter = counter + 1
  14. Loop Until counter = amount
  15. Debug.Print emailgroup

its returning the first email twice and stopping. i know my loop isnt right. can you help?
Sep 26 '07 #3
cyberdwarf
218 Expert 100+
The basic routine is:-
Expand|Select|Wrap|Line Numbers
  1. Dim RsDetails As New RecordsetDim SQL As String
  2.     SQL = "Select * from MyTable"
  3.     RsDetails.Open SQL, CurrentProject.Connection
  4.     Do Until RsDetails.EOF
  5.         Debug.Print RsDetails("Field1")
  6.         Debug.Print RsDetails("Field2")
  7.         RsDetails.MoveNext
  8.     Loop
  9.     RsDetails.Close
  10.     Set RsDetails = Nothing
HTH

Steve
Sep 26 '07 #4
Neekos
111 100+
im getting an error "either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record."


Here's my code:

Expand|Select|Wrap|Line Numbers
  1. Dim emailgroup as String
  2. Dim recordset As ADODB.recordset
  3. Dim SQL As String
  4.  
  5. Set recordset = New ADODB.recordset
  6. SQL = "SELECT * FROM qryAARP"
  7. recordset.Open SQL, CurrentProject.Connection
  8.  
  9. 'recordset.MoveFirst
  10.  
  11. Do Until recordset.EOF
  12. emailgroup = recordset("email")
  13. recordset.MoveNext
  14. emailgroup = emailgroup & ";" & recordset("email")
  15. Loop
  16. Debug.Print emailgroup
Sep 27 '07 #5
Neekos
111 100+
ok i fixed that error by adding the bold line


Expand|Select|Wrap|Line Numbers
  1. Dim emailgroup as String
  2. Dim recordset As ADODB.recordset
  3. Dim SQL As String
  4.  
  5. Set recordset = New ADODB.recordset
  6. SQL = "SELECT * FROM qryAARP"
  7. recordset.Open SQL, CurrentProject.Connection
  8.  
  9. 'recordset.MoveFirst
  10.  
  11. Do Until recordset.EOF
  12. emailgroup = recordset("email")
  13. recordset.MoveNext
  14. emailgroup = emailgroup & ";" & recordset("email")
  15. recordset.MoveNext
  16. Loop
  17. Debug.Print emailgroup

But i know my logic isnt right. I want the loop to continually concatenate each email. Right now its continually returning 2 emails. Can i get some help with this?
Sep 27 '07 #6
Neekos
111 100+
ok i got it to work with some change of code. I'll post the code in case anyone wants to know how to concatenate a string of multiple records. In this case its concatenating a list of emails.

Expand|Select|Wrap|Line Numbers
  1. Dim emailgroup As String
  2. Dim recordset As ADODB.recordset
  3. Dim SQL As String
  4.  
  5. emailgroup = ""
  6. Set recordset = New ADODB.recordset
  7. SQL = "SELECT * FROM qryTVLY"
  8. recordset.Open SQL, CurrentProject.Connection
  9.  
  10. Do While Not recordset.EOF
  11.   If emailgroup = "" Then
  12.     emailgroup = recordset!Email
  13.   Else
  14.     emailgroup = emailgroup & "; " & recordset!Email
  15.   End If
  16.   recordset.MoveNext
  17. Loop
  18. Debug.Print emailgroup
  19.  
  20. recordset.Close
  21. Set recordset = Nothing
Sep 27 '07 #7

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

Similar topics

1
by: LenS | last post by:
If this is the wrong place to post this, please advise better place. Otherwise, I have created the following python program and it works. Running on XP. I think I am now at that stage of learning...
2
by: Jayjay | last post by:
When it comes to access, I'm pretty good using the built in features and can come up with some pretty complex functions to get what I need. But we have this database I'm doing for work that is...
3
by: Iain Miller | last post by:
Can anybody help me with some Access 2000 code? I don't do a lot of coding in Access & so every time I come back to do something I pretty much have to relearn the syntax from scratch so this is...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
6
by: (Pete Cresswell) | last post by:
I *know* I've seen this before but can't remember where. Got a subform - pretty simple, actually. It's lined to a work table that contains comments related to a mutual fund. No problem...
2
by: Anand Ganesh | last post by:
Hi All, How to Implement Move Next, Move Previous, Last Record and First Record in a DataGrid Control ? Is there any standard tool available in the tool box button? Thanks for your time. ...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
1
by: Eric | last post by:
When I run my script it gives error on the following line: strEmail = Right(strEmail, (Len(strEmail) - 1)) I enclose my code and the sample text file too Thanks,...
10
by: ewankosayo | last post by:
Hi can anyone help me how can i move to the next record? While Reader.Read For Each Row As DataRow In Table.Rows If Reader("UserID") = Row("UserID") Then ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.