Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I signed up to your site to get help with a problem and I am so glad I did. I found the help I needed immediately. Thanks to all who contribute to your site..."

Geography

Where in the world do Tek-Tips members come from?

VBA Visual Basic for Applications (Microsoft) FAQ

VBA How To

Setting up a Data Source Name(DSN) programmatically in VB/VBA
Posted: 29 Jun 04 (Edited 6 Jul 04)

Normally in order to create an ODBC data source name (DSN) you have to, in NT4 anyway,  do it via Start->Settings->ControlPanel->Data Sources(ODBC). Once here you click on the ADD button and fill in the values on-screen as required. However this is no use if you are sending a program to clients and want the DSN to be set up automatically. I had just this problem recently. I need to have a text Driver DSN set up on my clients machine but didn't want them to have to do it as this is potentially a very error prone task. The good news is that it can be done programmatically. In the example below a text driver USER DSN is going to be set up but the example can be tweaked to set up any other kind of DSN you might require. Here's the code.


Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
(ByVal hwndparent As Long, ByVal frequest As Long, _
ByVal lpszdriver As String, ByVal lpszattributes As String) _
As Long

Sub Main()

Dim intret As Long
Dim atts As String
Dim strdriver As String

strdriver = "Microsoft Text Driver (*.txt; *.csv)"
atts = "DSN=" & "Text Files"
intret = SQLConfigDataSource(0, 1, strdriver, atts)

If intret Then
    Msgbox("DNS created sucessfully")
Else
    MsgBox ("There was a problem setting up the DSN, please contact support")
End If

End Sub

 

Back to VBA Visual Basic for Applications (Microsoft) FAQ Index
Back to VBA Visual Basic for Applications (Microsoft) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close