473,507 Members | 11,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating A DSN using VBA

38 New Member
Hi im using VBA to create A MYOB_ODBC User DSN

here is my code

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. 'Constant Declaration
  3.       Private Const ODBC_ADD_DSN = 1        ' Add data source
  4.       Private Const ODBC_CONFIG_DSN = 2     ' Configure (edit) data source
  5.       Private Const ODBC_REMOVE_DSN = 3     ' Remove data source
  6.       Private Const vbAPINull As Long = 0  ' NULL Pointer
  7.  
  8.  
  9.       'Function Declare
  10.       #If Win32 Then
  11.  
  12.           Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
  13.           (ByVal hwndParent As Long, ByVal fRequest As Long, _
  14.           ByVal lpszDriver As String, ByVal lpszAttributes As String) _
  15.           As Long
  16.       #Else
  17.           Private Declare Function SQLConfigDataSource Lib "ODBCINST.DLL" _
  18.           (ByVal hwndParent As Integer, ByVal fRequest As Integer, ByVal _
  19.           lpszDriver As String, ByVal lpszAttributes As String) As Integer
  20.       #End If
  21.  
  22.  
  23.  
  24.  
  25.  
  26. Private Sub Command0_Click()
  27.       #If Win32 Then
  28.           Dim intRet As Long
  29.       #Else
  30.           Dim intRet As Integer
  31.       #End If
  32.       Dim strDriver As String
  33.       Dim strAttributes As String
  34.  
  35.       'Set the driver to SQL Server because it is most common.
  36.       strDriver = "MYOB_ODBC"
  37.       'Set the attributes delimited by null.
  38.       'See driver documentation for a complete
  39.       'list of supported attributes.
  40.       'strAttributes = "SERVER=SomeServer" & Chr$(0)
  41.       strAttributes = strAttributes & "DESCRIPTION=Temp DSN" & Chr$(0) '' the Description
  42.       strAttributes = strAttributes & "DSN=DSN_TEMP" & Chr$(0)         '' The DataSourceName
  43.       strAttributes = strAttributes & "DATABASE=C:\myob15\Clearwtr.MYO" & Chr$(0)
  44.       'strAttributes = strAttributes & "CFP=C:\myob15\Clearwtr.MYO" & Chr$(0)
  45.       'To show dialog, use Form1.Hwnd insteCreating Aad of vbAPINull.
  46.       intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
  47.       strDriver, strAttributes)
  48.  
  49.       If intRet Then
  50.           MsgBox "DSN Created"
  51.       Else
  52.           MsgBox "Create Failed"
  53.       End If
  54. End Sub
  55.  
  56.  
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
Apr 17 '07 #1
0 2029

Sign in to post your reply or Sign up for a free account.

Similar topics

15
6719
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
3
1843
by: Ken Varn | last post by:
I am just starting the process of creating ASP.NET server controls. I have created controls for .NET applications, but have just started with ASP.NET. I am a little confused about some areas that...
3
1040
by: Ken Varn | last post by:
I am just starting the process of creating ASP.NET server controls. I have created controls for .NET applications, but have just started with ASP.NET. I am a little confused about some areas that...
6
339
by: Ken Varn | last post by:
I am just starting the process of creating ASP.NET server controls. I have created controls for .NET applications, but have just started with ASP.NET. I am a little confused about some areas that...
9
2963
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I read somewhere "using kernel stuff in thread is not good.." if ManualResetEvent object is created in thread but not actually used, will it affect performance? Bob
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.