Solved

putting up DSN in vb6

Posted on 2004-08-05
3
704 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 69

Expert Comment

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

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

Accepted Solution

by:
Éric Moreau earned 50 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now