Results 1 to 1 of 1
2012-08-23, 21:22 #1
- Join Date
- Sep 2007
- Thanked 1 Time in 1 Post
Word 2010 and SQL Server: Attach database to a Userform for a letter macro
I have not worked with databases at all, so I`m hoping that someone can help me. I am trying to attach a SQL database to the letterhead so the user would type in a matter number and/or a client number, and the macro would then be able to grab the name, address, re, etc. from the database and insert the information into the userform. The user then would have a chance to review and change any of the information before the letter is created. I have searched the internet for a while now and have tried many things, but can't seem to get a connection to work. I have created a .dsn file, but get an Object Variable not set error when trying to use it.
Dim vConnection As ADODB.Connection, strConnect As String Dim vRecordSet As ADODB.Recordset, vCommand As ADODB.Command vConnection.ConnectionString = "C:\MRCustom\MacroFiles\MRLetterQuery.dsn" & "Provider=SQLOLEDB;" vConnection.Open
vConnection.ConnectionString = "DRIVER=SQL Server;SERVER=DB2;DATABASE=son_db" vConnection.Open If vConnection.State = adStateOpen Then MsgBox "Finally!!" Else MsgBox "You suck!!" End If
I can't seem to get anywhere with this. What I would ultimately like is to be able to connect using the .dsn file, and then use an sql query to extract the appropriate fields, put the data in a proper letter format and insert that into the userform. I'm starting to wonder if this is even possible? I am on Windows 7 and Word 2010. It is a SQL Server driver using a trusted connection, but no password.
What am I doing wrong?
Thanking you in advance for your help.
Last edited by maverik; 2012-08-27 at 19:13. Reason: No response so trying a different room