Important alert: (current site time 7/15/2013 7:42:47 PM EDT)
 

article

Send Fax With T-SQL Using MS-Word

Email
Submitted on: 5/30/2005 5:09:42 AM
By: TheIndoctrinator !!  
Level: Advanced
User Rating: By 5 Users
Compatibility: SQL Server 2000, SQL Server 7.0
Views: 12441
author picture
(About the author)
 
     Hi This is My Fourth Submission named "Send Fax With T-SQL Using MS-Word. The following example, ("Full Commented to make it understand by VB Developers"), creates a Word document and retrieves its Application object, which it stores in an Integer variable which represents the COM pointer to the automation interface of the component. Next, it makes the Word application visible by setting the Application's Visible property to True, then it inserts some text into the Word document and finally faxes the document using the SendFax method. Obviously you can use such stored procedures from triggers or other stored procedures, and invoke them from client applications or from the SQL Server Agent. Sql Server OLE Automation example by Giuseppe Dimauro 04/2000. Many Many Thanx to Him and all other developers.... (May be this time i could win Code Of The Day with full help of G.D. )

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				
/*Sql Server OLE Automation example by Giuseppe Dimauro 04/2000. Many Many Thanx to Him and all other developers....*/
DECLARE @WordDocument int
DECLARE @WordApplication int
DECLARE @Content int
DECLARE @visible int
DECLARE @hr int
DECLARE @text varchar(4096)
-- Set WordDocument = CreateObject("Word.Document")
EXEC @hr = sp_OACreate 'word.Document', @WordDocument OUT
-- Set Application = WordDocument.Application
IF @hr = 0
EXEC @hr = sp_OAGetProperty @WordDocument, 'Application', @WordApplication OUT
-- Set Content = WordDocument.Content
IF @hr = 0
EXEC @hr = sp_OAGetProperty @WordDocument, 'Content', @Content OUT
-- Content.Text = "Word Document " + vbNewLine + "generated by SQL Server"
IF @hr = 0
BEGIN
set @text = 'Word Document' + char(10) + 'generated by SQL Server'
EXEC @hr = sp_OASetProperty @Content, 'Text', @text
END
-- WordApplication.Visible = True
IF @hr = 0
BEGIN
EXEC @hr = sp_OASetProperty @WordApplication, 'Visible', 1
waitfor delay '00:00:10'
END
-- WordDocument.SendFax "", "Send a fax from SQL Server"
IF @hr = 0
EXEC @hr = sp_OAMethod @WordDocument, 'SendFax', NULL, '', 'Invio fax da SQL Server'
IF @hr <> 0
BEGIN
print "ERROR OCCURRED: " + cast(@hr as varchar(128))
RETURN
END
--Do Not Forgot to Vote...


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
5/30/2005 6:31:57 AMThe VB Guy

Although the formating is not good but the code itself is informative... 5 globes from me to you and G.D.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.