Link to home
Start Free TrialLog in
Avatar of stromberg45
stromberg45

asked on

putting up DSN in vb6

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.
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

I think you forgot a \

strAttributes = strAttributes & "DATABASE=" & App.Path & "\RM.mdb" & Chr$(0)
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stromberg45
stromberg45

ASKER

thansk for that emoreau, worked perfectly !!