Hi im using VBA to create A MYOB_ODBC User DSN
here is my code
It creates the DSN fine, the problem is that i need to specify the database to use for the connection, but the MYOB_ODBC driver manual says that if a DSN is specified it will ignore the DATABASE Keyword.
Is there anyway around this issue so that i can specify the databse connection on the command0 click, or can this DATABASE Keyword be specified after the dns creation, please help as this is really holding up the project that i am working on
here is my code
Code:
Option Compare Database
'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 vbAPINull As Long = 0 ' NULL Pointer
'Function Declare
#If Win32 Then
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
#Else
Private Declare Function SQLConfigDataSource Lib "ODBCINST.DLL" _
(ByVal hwndParent As Integer, ByVal fRequest As Integer, ByVal _
lpszDriver As String, ByVal lpszAttributes As String) As Integer
#End If
Private Sub Command0_Click()
#If Win32 Then
Dim intRet As Long
#Else
Dim intRet As Integer
#End If
Dim strDriver As String
Dim strAttributes As String
'Set the driver to SQL Server because it is most common.
strDriver = "MYOB_ODBC"
'Set the attributes delimited by null.
'See driver documentation for a complete
'list of supported attributes.
'strAttributes = "SERVER=SomeServer" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0) '' the Description
strAttributes = strAttributes & "DSN=DSN_TEMP" & Chr$(0) '' The DataSourceName
strAttributes = strAttributes & "DATABASE=C:\myob15\Clearwtr.MYO" & Chr$(0)
'strAttributes = strAttributes & "CFP=C:\myob15\Clearwtr.MYO" & Chr$(0)
'To show dialog, use Form1.Hwnd insteCreating Aad of vbAPINull.
intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
strDriver, strAttributes)
If intRet Then
MsgBox "DSN Created"
Else
MsgBox "Create Failed"
End If
End Sub
Is there anyway around this issue so that i can specify the databse connection on the command0 click, or can this DATABASE Keyword be specified after the dns creation, please help as this is really holding up the project that i am working on