Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2006, 12:12 PM
Registered User
 
Join Date: Mar 2006
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

 
Old March 11th, 2006, 06:15 AM
Authorized User
 
Join Date: Mar 2006
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





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





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