Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 9th, 2006, 12:12 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Database Printing Recordset VB6

Hey,

New Poster, Ok I have the below code, what I would like it to do is load word 2003 up then print all the users from my database in a long list down the page, But I am not sure how to get it working lol

At present all it prints is the first username!

------------------------VB Code Start----------------------------

Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub Command1_Click()

Dim ssql As String
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Staff.mdb"
con.Open

ssql = "select Username from LoginID"
rs.Open ssql, con, adOpenDynamic, adLockOptimistic

Dim oApp As Word.Application
    Dim oDoc As Word.Document
    Set oApp = New Word.Application
    Set oDoc = oApp.Documents.Open("Doc1.doc")

   oApp.Selection.TypeText Text:=rs!UserName
    oApp.Documents.Open ("Doc1.doc")

End Sub

-----------------------VB Code End--------------------------


Any help would be great thanks

Alex

Reply With Quote
  #2 (permalink)  
Old March 11th, 2006, 06:15 AM
Authorized User
 
Join Date: Mar 2006
Location: Chennai, Tamil Nadu, India.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Raghunathan
Default

hi,

your code is perfect but u've to do a small addition to the code to make it work as asked

you've to run a loop to browse thru all the records in the recordset and print it in word thats all

------------------------VB Code Start----------------------------

Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub Command1_Click()

Dim ssql As String
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Staff.mdb"
con.Open

ssql = "select Username from LoginID"
rs.Open ssql, con, adOpenDynamic, adLockOptimistic

Dim oApp As Word.Application
    Dim oDoc As Word.Document
    Set oApp = New Word.Application
    Set oDoc = oApp.Documents.Open("Doc1.doc")

   '----------Start Of Code--------------------------------
   'Run a Loop To Browse Thru The Recordset, until it reaches the last recordset
   Do While Not rs.EOF
       oApp.Selection.TypeText Text:=rs!UserName
       rs.MoveNext 'Move the Recordpointer to the next record
   Loop
   '----------End Of Code--------------------------------
   oApp.Documents.Open ("Doc1.doc")

End Sub

-----------------------VB Code End--------------------------

Regards,
Raghu
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordset database cyber_kaley20 Beginning PHP 0 December 11th, 2007 03:43 AM
database and vb6 Probie VB Databases Basics 3 August 2nd, 2007 01:14 PM
Vb6 access 97 recordset problem Probie VB Databases Basics 3 August 1st, 2007 06:12 PM
VB6 ComboBox Source from Recordset tsehenuk VB Databases Basics 3 April 12th, 2005 04:41 PM
VB6 database ADO recordset error tsehenuk Beginning VB 6 12 January 31st, 2005 07:33 PM



All times are GMT -4. The time now is 02:15 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.