A Little Macro To Automate Creating Connection Strings - ISerializable - Roy Osherove's Blog

A Little Macro To Automate Creating Connection Strings

I've created a little macro that automatically creates a connection string and inserts it in your code. It pops up the infamous "Data Links" dialog for you, saving you, the poor programmer, from having to remember all those pesky little syntax details.... :)

No references needed for this. Thank god for CreateObject :)

Public Sub InsertConnectionString()

Dim links As Object = CreateObject("DataLinks")

Dim cn As Object = CreateObject("ADODB.Connection")

 

links.PromptEdit(cn)

If cn.connectionstring = "" Then Exit Sub

 

Dim sel As TextSelection = ActiveDocument().Selection

sel.Text = cn.connectionstring

End Sub

Now just add a shortcut for it and you're ready to roll...

Published Monday, June 23, 2003 12:44 AM by RoyOsherove

Comments

Sunday, June 22, 2003 9:09 PM by Jonne Kats

# re: A Little Macro To Automate Creating Connection Strings

Thanks man,

I am definetly going to use this...
Wednesday, February 18, 2004 8:51 PM by Tallion

# re: A Little Macro To Automate Creating Connection Strings

works great in vb.net. Thanks!
Tuesday, January 30, 2007 3:50 PM by Faizan Sheikh

# re: A Little Macro To Automate Creating Connection Strings

TextSelection is not a defined name for me. I think it is a class, and if so, please provide the code for TextSelection. Thanks