Hi everyone,

I'm a seasoned programmer, but I've yet to touch VBScript. I want to
write a script that will query a database and print contents to a
printer based on entries within the database. So for example I'd have
the following printers setup on the workstation:

\\printsvr\marketingptr
\\printsvr\hrptr
\\printsvr\itptr

And the database might have a table similar to this:

PrinterName ContentBody
marketing THis is a test message for Marketing
hr THis is a test message for Human Resources
it This is a test message for Information
Technology

When the script runs it will parse the database table and print the
content to the specific printer. This is of course a simple example,
I'll probably have a table linking the PrinterName to the Printer UNC,
but you get the idea of what I'm trying to do.

I have no working knowledge of VBScript, so I'm not even sure if this
is possible, or if so what commands I'll need to use. If someone has a
script that does this, I'd love to take a gander, but if someone can
point me in the right direction with commands to research, that'd be
wonderful. The two components I know I need are a component to hit the
database (which is Microsoft SQL 2000) and a component to print to the
specified printer (which will all be setup on the local workstation).

Thanks again for any assistance...

Alex

Re: Printing data from MS SQL to various printers by Sofia

Sofia
Thu Aug 17 12:55:31 CDT 2006

Hi Alex! :)

Here's a example of a simple search in a sql database.
I've never needed to print from a script so I can't help you there but I bet
someone else will. :)


Option Explicit

Dim strToFind, objADODBConnection, strConnectionString, strQuery,
objRecordSet
strToFind="something"

Set objADODBConnection = CreateObject("ADODB.Connection")

strConnectionString = "DRIVER=SQL Server;Trusted_Connection=Yes;
DATABASE=myLittlePrintMessageDataBase;SERVER=dbserver.domain.com"
objADODBConnection.Open(strConnectionString)

strQuery = "SELECT * FROM MessageTable WHERE PrinterName LIKE
'"+strToFind+"' ORDER BY PrinterName"
Set objRecordSet = objADODBConnection.Execute(strQuery)

Do Until objRecordSet.EOF
WScript.Echo(CStr(objRecordSet.Fields("PrinterName").Value))
WScript.Echo(CStr(objRecordSet.Fields("ContentBody").Value))
objRecordSet.MoveNext()
Loop

objRecordSet.Close() : Set objRecordSet = Nothing
objADODBConnection.Close() : Set objADODBConnection = Nothing


I've just cut a bit of a script I made recentlly and changed all the server
names and such so there might be some errors but since you're a programmer
that shouldn't matter. You'll get the point. Very simple. :)

Have a nice day! :)

/Sofia


"Alex" <samalex@gmail.com> wrote in message
news:1155822000.516144.134820@h48g2000cwc.googlegroups.com...
> Hi everyone,
>
> I'm a seasoned programmer, but I've yet to touch VBScript. I want to
> write a script that will query a database and print contents to a
> printer based on entries within the database. So for example I'd have
> the following printers setup on the workstation:
>
> \\printsvr\marketingptr
> \\printsvr\hrptr
> \\printsvr\itptr
>
> And the database might have a table similar to this:
>
> PrinterName ContentBody
> marketing THis is a test message for Marketing
> hr THis is a test message for Human Resources
> it This is a test message for Information
> Technology
>
> When the script runs it will parse the database table and print the
> content to the specific printer. This is of course a simple example,
> I'll probably have a table linking the PrinterName to the Printer UNC,
> but you get the idea of what I'm trying to do.
>
> I have no working knowledge of VBScript, so I'm not even sure if this
> is possible, or if so what commands I'll need to use. If someone has a
> script that does this, I'd love to take a gander, but if someone can
> point me in the right direction with commands to research, that'd be
> wonderful. The two components I know I need are a component to hit the
> database (which is Microsoft SQL 2000) and a component to print to the
> specified printer (which will all be setup on the local workstation).
>
> Thanks again for any assistance...
>
> Alex
>