[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

putting up DSN in vb6

Posted on 2004-08-05
3
Medium Priority
?
712 Views
Last Modified: 2013-12-25
g'day, i have read other people's questions about putting up DSN, and used some code in them. i find when i use the code, it's puts up the DSN that does not point to a database.

so it works, but just doesn't select the database. it's an access database. here is the code i use.

Public Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
          (ByVal hwndParent As Long, ByVal fRequest As Long, _
          ByVal lpszDriver As String, ByVal lpszAttributes As String) _
          As Long

      'Constant Declaration
      Private Const ODBC_ADD_DSN = 1        ' Add data source
      Private Const ODBC_CONFIG_DSN = 2     ' Configure (edit) data source
      Private Const ODBC_REMOVE_DSN = 3     ' Remove data source
      Private Const ODBC_ADD_SYS_DSN = 4    ' add a new system data source
      Private Const vbAPINull As Long = 0


      Dim intRet As Long
      Dim strDriver As String
      Dim strAttributes As String

      strDriver = "Microsoft Access Driver (*.mdb)"
      strAttributes = "SERVER=SomeServer" & Chr$(0)
      strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0)
      strAttributes = strAttributes & "DSN=RM TEMP" & Chr$(0)
      strAttributes = strAttributes & "DATABASE=" & App.Path & "RM.mdb" & Chr$(0)

      intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, strDriver, strAttributes)

thanks.
0
Comment
Question by:stromberg45
  • 2
3 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 11726506
I think you forgot a \

strAttributes = strAttributes & "DATABASE=" & App.Path & "\RM.mdb" & Chr$(0)
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 200 total points
ID: 11726530
shouldn't it be:
strAttributes & "DESCRIPTION=Temp SN" & Chr$(0)
strAttributes = strAttributes & "DSN=RM TEMP" & Chr$(0)
strAttributes = strAttributes & "DBQ='" &  App.Path & "\RM.mdb'" & Chr$(0)
strAttributes = strAttributes & "UID=username" & Chr$(0)
strAttributes = strAttributes & "PWD=password" & Chr$(0)
0
 

Author Comment

by:stromberg45
ID: 11749636
thansk for that emoreau, worked perfectly !!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month19 days, 2 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question