473,777 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Iteration problem with Do Until rstOutput.EOF

When doing a mail merge with Word, I can't seem to get the below
(abbreviated) routine to iterate strBookmark01 -- it just uses the first
name in the recordset for all 10 (or whatever) documents...

Is there some other code I need to get the string to iterate with each name?
Thanks in advance...

Set rstOutput = db.OpenRecordse t("qryMailMerge ")
Do Until rstOutput.EOF
strBookmark01 = rstData!Name
With objWord
.Selection.GoTo what:=wdGoToBoo kmark, Name="Bookmark0 1"
.Slection.TypeT ext Text:=strBookma rk01
End With
Nov 12 '05 #1
9 4373
"deko" <dj****@hotmail .com> wrote:
it just uses the first
name in the recordset for all 10 (or whatever) documents...

Is there some other code I need to get the string to iterate with each
name?


I'm no expert, but I'm surprised you're getting anything because you've
opened the recordset but not set the pointer to any record. I think you
need to use MoveFirst and MoveNext statements as appropriate.

Regards,
Keith.
Nov 12 '05 #2
On 3 Dec 2003 13:51:56 GMT, Keith Wilby
<ke*********@Aw ayWithYerCrap.c om> wrote:

MoveFirst is not needed. A new recordset is either at EOF if no rows,
or at the first record.
But the fellow needs MoveNext, as well as the Loop instruction at the
bottom of the loop. The code as presented will not compile.

-Tom.
"deko" <dj****@hotmail .com> wrote:
it just uses the first
name in the recordset for all 10 (or whatever) documents...

Is there some other code I need to get the string to iterate with each
name?


I'm no expert, but I'm surprised you're getting anything because you've
opened the recordset but not set the pointer to any record. I think you
need to use MoveFirst and MoveNext statements as appropriate.

Regards,
Keith.


Nov 12 '05 #3
Tom van Stiphout <to*****@no.spa m.cox.net> wrote:
MoveFirst is not needed. A new recordset is either at EOF if no rows,
or at the first record.


Thanks Tom, duly noted :-)
Nov 12 '05 #4
Thanks for the tip... I am reviewing the code now and will re-post revision
and results...

"Tom van Stiphout" <to*****@no.spa m.cox.net> wrote in message
news:e7******** *************** *********@4ax.c om...
On 3 Dec 2003 13:51:56 GMT, Keith Wilby
<ke*********@Aw ayWithYerCrap.c om> wrote:

MoveFirst is not needed. A new recordset is either at EOF if no rows,
or at the first record.
But the fellow needs MoveNext, as well as the Loop instruction at the
bottom of the loop. The code as presented will not compile.

-Tom.
"deko" <dj****@hotmail .com> wrote:
it just uses the first
name in the recordset for all 10 (or whatever) documents...

Is there some other code I need to get the string to iterate with each
name?


I'm no expert, but I'm surprised you're getting anything because you've
opened the recordset but not set the pointer to any record. I think you
need to use MoveFirst and MoveNext statements as appropriate.

Regards,
Keith.


Nov 12 '05 #5
to*****@no.spam .cox.net (Tom van Stiphout) wrote in
<e7************ *************** *****@4ax.com>:
On 3 Dec 2003 13:51:56 GMT, Keith Wilby
<ke*********@A wayWithYerCrap. com> wrote:

MoveFirst is not needed. A new recordset is either at EOF if no
rows, or at the first record.
But the fellow needs MoveNext, as well as the Loop instruction at
the bottom of the loop. The code as presented will not compile.


MoveFirst may be unnecessary, but I always explicitly include it,
anyway, just so it's clear where we're starting from.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #6
Hi and thanks for the reply.

I do have a Move.Next on line 84
The problem is on line 43 and following - the string variables get stuck on
the first value in the recordset. For example, if there are 10 records in
the recordset, Word opens 10 documents, all addressed to the same person.

The purpose of this code is to allow the user to select a set of records for
use in a mail merge (see line 21 and following).
Also, a predefiend series of Bookmark "handles" (lines 3 - 9) allow the user
to create custom Word Templates using Bookmarks named after these handles.

Another problem I'm having is with the Do Loop (line 41). I'm not sure what
recordset to use here...

again, thanks for your comments!

1 Public Function WordDoc()
2 'predefined merge fields
3 Dim strReturnAddres s As String
4 Dim strFirstName
5 Dim strLastName
6 Dim strFullName As String
7 Dim strSalutation As String
8 Dim strNameAddressB lock As String
9 Dim strAddressOnly As String
10
11 Dim rsEntity As DAO.Recordset
12 Dim rsAddress As DAO.Recordset
13 Dim rsReturnAddress As DAO.Recordset
14 Dim rsOutput As DAO.Recordset
15 Dim rst As DAO.Recordset
16 Dim objWord As Word.Applicatio n
17 Dim db As DAO.Database
18 'open word (code omitted)
19
20 Set db = CurrentDb
21 strRsDef = DLookup("RecSel ", "tblOutput" )
22 Select Case strRsDef
23 Case 0
24 strQry = "tblEntity"
25 Set rsEntity = db.OpenRecordse t("SELECT ... code omitted)
26 Set rsAddress = db.OpenRecordse t("SELECT ... code omitted)
27 Case 1
28 strQry = DLookup("Search Qry", "tblOutput" )
29 Set rsEntity = db.OpenRecordse t("SELECT ... code omitted)
30 Set rsAddress = db.OpenRecordse t("SELECT ... code omitted)
31 Case 2
32 strQry = "qryMergeCa t"
33 Set rsEntity = db.OpenRecordse t("qryMergeCat" )
34 Set rsAddress = db.OpenRecordse t("qryMergeCat" )
35 Case Else
36 Exit Function
37 End Select
38 Set rsReturnAddress = db.OpenRecordse t("qryRtAdd")
39 Set rsOutput = db.OpenRecordse t(strQry) ' >>>>> not sure about
this...
40
41 Do Until rsOutput.EOF '>>>> should this be Do Until rsEntity.EOF ??
42
43 '>>>>>> value of strNameAddressB lock (and other strings) not iterating
through recordset
44 strNameAddressB lock = IIf(IsNull(rsEn tity!Prefix), "",
rsEntity!Prefix & " ") & _
45 IIf(IsNull(rsEn tity!FirstName) , "", rsEntity!FirstN ame) &
_
46 IIf(IsNull(rsEn tity!MiddleName ), "", " " &
rsEntity!Middle Name) & _
47 " " & rsEntity!LastNa me & IIf(IsNull(rsEn tity!Suffix), "",
", " & rsEntity!Suffix ) & _
48 IIf(IsNull(rsEn tity!Company), "", Chr(13) & Chr(10) &
Chr(9) & Chr(9) & rsEntity!Compan y) & _
49 IIf(IsNull(rsAd dress!Address1) , "", Chr(13) & Chr(10) &
Chr(9) & Chr(9) & rsAddress!Addre ss1) & _
50 IIf(IsNull(rsAd dress!Address2) , "", Chr(13) & Chr(10) &
Chr(9) & Chr(9) & rsAddress!Addre ss2) & _
51 IIf(IsNull(rsAd dress!Address3) , "", Chr(13) & Chr(10) &
Chr(9) & Chr(9)) & rsAddress!Addre ss3 & _
52 IIf(IsNull(rsAd dress!City), "", Chr(13) & Chr(10) & Chr(9)
& Chr(9) & rsAddress!City) & _
53 IIf(IsNull(rsAd dress!State), "", ", " & rsAddress!State ) &
_
54 IIf(IsNull(rsAd dress!Zipcode), "", " " &
rsAddress!Zipco de)
55
56 strReturnAddres s = (code omitted)
57 strFirstName = (code omitted)
58 strLastName = (code omitted)
59 strFullName = (code omitted)
60 strSalutation = (code omitted)
61 strAddressOnly = (code omitted)
62
63 With objWord
64 On Error Resume Next 'skip over bookmarks that don't exist in
selected template
65 .Documents.Add Template:=strTe mplate, NewTemplate:=Fa lse,
DocumentType:=0
66 .Selection.GoTo what:=wdGoToBoo kmark, Name:="NameAddr essBlock"
67 .Selection.Type Text Text:=strNameAd dressBlock
68 .Selection.GoTo what:=wdGoToBoo kmark, Name:="ReturnAd dress"
69 .Selection.Type Text Text:=strReturn Address
70 .Selection.GoTo what:=wdGoToBoo kmark, Name:="FirstNam e"
71 .Selection.Type Text Text:=strFirstN ame
72 .Selection.GoTo what:=wdGoToBoo kmark, Name:="LastName "
73 .Selection.Type Text Text:=strLastNa me
74 .Selection.GoTo what:=wdGoToBoo kmark, Name:="FullName "
75 .Selection.Type Text Text:=strFullNa me
76 .Selection.GoTo what:=wdGoToBoo kmark, Name:="Salutati on"
77 .Selection.Type Text Text:=strSaluta tion
78 .Selection.GoTo what:=wdGoToBoo kmark, Name:="AddressO nly"
79 .Selection.Type Text Text:=strAddres sOnly
80 .Application.No rmalTemplate.Sa ved = True
81 End With
82 On Error GoTo 0
83 If strRsDef = "0" Then GoTo Finish
84 rsOutput.MoveNe xt
85 Loop
86 Finish: 'close objects (code omitted)
87 End Function

"Tom van Stiphout" <to*****@no.spa m.cox.net> wrote in message
news:e7******** *************** *********@4ax.c om...
On 3 Dec 2003 13:51:56 GMT, Keith Wilby
<ke*********@Aw ayWithYerCrap.c om> wrote:

MoveFirst is not needed. A new recordset is either at EOF if no rows,
or at the first record.
But the fellow needs MoveNext, as well as the Loop instruction at the
bottom of the loop. The code as presented will not compile.

-Tom.
"deko" <dj****@hotmail .com> wrote:
it just uses the first
name in the recordset for all 10 (or whatever) documents...

Is there some other code I need to get the string to iterate with each
name?


I'm no expert, but I'm surprised you're getting anything because you've
opened the recordset but not set the pointer to any record. I think you
need to use MoveFirst and MoveNext statements as appropriate.

Regards,
Keith.


Nov 12 '05 #7
On Wed, 03 Dec 2003 20:07:58 GMT, dX********@bway .net.invalid (David
W. Fenton) wrote:

I'll allow it :-), but be sure to first test for a non-empty
recordset. Otherwise MoveFirst will fail.
-Tom.

to*****@no.spa m.cox.net (Tom van Stiphout) wrote in
<e7*********** *************** ******@4ax.com> :
On 3 Dec 2003 13:51:56 GMT, Keith Wilby
<ke*********@ AwayWithYerCrap .com> wrote:

MoveFirst is not needed. A new recordset is either at EOF if no
rows, or at the first record.
But the fellow needs MoveNext, as well as the Loop instruction at
the bottom of the loop. The code as presented will not compile.


MoveFirst may be unnecessary, but I always explicitly include it,
anyway, just so it's clear where we're starting from.


Nov 12 '05 #8
On Wed, 03 Dec 2003 20:07:58 GMT in comp.databases. ms-access,
dX********@bway .net.invalid (David W. Fenton) wrote:
to*****@no.spa m.cox.net (Tom van Stiphout) wrote in
<e7*********** *************** ******@4ax.com> :
On 3 Dec 2003 13:51:56 GMT, Keith Wilby
<ke*********@ AwayWithYerCrap .com> wrote:

MoveFirst is not needed. A new recordset is either at EOF if no
rows, or at the first record.
But the fellow needs MoveNext, as well as the Loop instruction at
the bottom of the loop. The code as presented will not compile.


MoveFirst may be unnecessary, but I always explicitly include it,
anyway, just so it's clear where we're starting from.


I had a situation recently where the client has requested something
unatrual for a database to do, in an MTO or requisition they want a
start and end item number so they enter start item 1, end item 20, qty
20. This will later be split down upon reciept and the individual item
given a UID, the last part being nothing I've not done before of
course it's the first part is peculiar to the way they work.

No if they enter item 1 to 20, you can't have say item 11 elsewhere,
etc, in the beforeupdate I created a recordsetclone and looped
through, I always had put .MoveFirst in the past but this time I
didn't (laziness I guess) and it would never trap the first attempt
after opening the form, upon debugging I found it looped just one
record so it had started at the last record.

I'll not be making that mistake again.

--
A)bort, R)etry, I)nfluence with large hammer.
Nov 12 '05 #9
to*****@no.spam .cox.net (Tom van Stiphout) wrote in
<gv************ *************** *****@4ax.com>:
On Wed, 03 Dec 2003 20:07:58 GMT, dX********@bway .net.invalid
(David W. Fenton) wrote:

I'll allow it :-), but be sure to first test for a non-empty
recordset. Otherwise MoveFirst will fail.


Well, I assumed that in my answer.

I never check for anything but .RecordCount <> 0 (assuming I'm
going to move through the recordset).

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
3748
by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ------------------------------------------------------------- PEP: 323
59
4345
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The HTML version is much more readable than the ReST version. See: http://www.python.org/peps/pep-0322.html
31
2999
by: Raymond Hettinger | last post by:
Based on your extensive feedback, PEP 322 has been completely revised. The response was strongly positive, but almost everyone preferred having a function instead of multiple object methods. The updated proposal is at: www.python.org/peps/pep-0322.html In a nutshell, it proposes a builtin function that greatly simplifies reverse iteration. The core concept is that clarity comes from specifying a sequence in a forward direction and...
2
2081
by: Abdullah Khaidar | last post by:
Is there any iteration style we must use to get faster processing time? I've tried with some style to concat number in list. But I still don't know which one is the recommended style. >>> def useListIteration(): list = result = "" for item in list: result += item return result
3
3619
by: Dustin Wilson | last post by:
I have a problem with the following line of code. rstOutput! = FormatDateTime("January 1, 2004", vbLongDate) When I run this on my computer at home it runs without problem but when I run it at work I get a Run-time error '3421' Data type conversion error. I'm really stumped as to why this is. Both computers are Windows 2000 SP4 with Access 2000. The field is a Date/Time field with a format of Long Date set. Does anyone have an idea...
28
7411
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are "good" in such terms, that this core data structure is changed only by atomic operations, so that the data structure is always consistent regarding the application. Only the change-operations on the dicts and lists itself seem to cause problems...
18
3723
by: MTD | last post by:
Hello all, I've been messing about for fun creating a trial division factorizing function and I'm naturally interested in optimising it as much as possible. I've been told that iteration in python is generally more time-efficient than recursion. Is that true? Here is my algorithm as it stands. Any suggestions appreciated!
9
4052
by: news.microsoft.com | last post by:
I am looping through an iteration and I would like to test the next item but if its not the one that I want how do I put it back so that when my foreach continues it is in the next iteration? Bill
4
3655
by: John A Grandy | last post by:
Is there a performance difference between forward iteration and reverse iteration through a List<string? for ( i = 0; i < myList.Count; i++ ) { // do work, such as forward iterate through a subset of myList ... } vs
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.