Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA and mySQL statements

Status
Not open for further replies.

beckyr51

Programmer
Jan 29, 2008
36
IE
Hi im trying to get access to print out email addresses in a word document using a recordset but while the document is opening nothing is printing out. Is there something wrong with my syntax? Any help please, here's my code:

retiring = InputBox("Enter the Code of the Tutor Retiring", "Retiring Tutor")
Set rs = db.OpenRecordset("Select [STU_EMAIL] from [tblStudents] where tblStudents.[STU_TU_CODE] = " & "'" & retiring & "';")
TheAddress = rs![STU_EMAIL]
rs.MoveFirst
Do While Not rs.EOF

With WordObj.ActiveDocument.Bookmarks
ActiveDocument.Bookmarks("bmk1").Range.Text = TheAddress
End With


rs.MoveNext
Loop
 
Does TheAddress contain data (i.e. not a NULL return from the DB)?

You set the value of TheAddress outside the loop, so the value will never change. You also set the same value within the loop, do you need the loop at all?

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
may change
With WordObj.ActiveDocument.Bookmarks
ActiveDocument.Bookmarks("bmk1").Range.Text = TheAddress
End With

to this

With WordObj.ActiveDocument
.Bookmarks("bmk1").Range.Text = TheAddress
End With

ck1999
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top