Solved

Create ODBC via VBA for access

Posted on 2010-08-24
6
771 Views
Last Modified: 2013-11-27
I have an access front end that references a SQL backend.  I have the
ODBC connection connecting the front end to the back end set up on my pc and it works fine.  

My problem occurs when I distribute the front end to another user with out the ODBC connection
set up on their PC.  They recieve an error.  I have to distribute to a number of users but I do
not want them to set up the ODBC connection since that task is error prone and the users and not
all savy with computers.

how can I use VBA to set up the connection? Please use examples in your code.
0
Comment
Question by:RDLFC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 4

Accepted Solution

by:
Clothahump earned 167 total points
ID: 33516898
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset

cnn.Open "YourDSN", "YourUsername", "YourPassword"
rs.ActiveConnection = cnn
rs.CursorLocation = adUseServer

rs.Source = "SELECT * FROM TABLE WHERE FIELD='data'"
rs.Open
' code goes here to manipulate the recordset retrieved
rs.Close

Set rs = Nothing
Set cnn = Nothing


If you don't have a DSN established, look at www.ConnectionStrings.com and find a connection string that fits your needs to use in the cnn.open line.
0
 

Author Comment

by:RDLFC
ID: 33517796
thanks i will check out your solution when I get to work tomorrow.
0
 
LVL 50

Assisted Solution

by:Gustav Brock
Gustav Brock earned 167 total points
ID: 33518807
Here is a full module with all functions for performing this.
Copy and paste into a new module and omit the first line:
Attribute VB_Name = "basWinAPI_DSN"

Study the in-line comments for typical usage and examples.
Note that the Private functions are for internal use - by the Public functions.

Be aware, that limited user rights may prohibit creation of DSN entries.

/gustav
basWinAPI-DSN.txt
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 15

Assisted Solution

by:fsze88
fsze88 earned 166 total points
ID: 33518851
I suggest

the result is

rst.CursorLocation = adUseClient
rst.CursorType = adOpenStatic
rst.LockType = adLockBatchOptimistic
should be better and able to reconnect to database several time
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset


Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset


cnn.Open "dsn", "user", "pwd"
rst.ActiveConnection = cnn
rst.CursorLocation = adUseClient
rst.CursorType = adOpenStatic
rst.LockType = adLockBatchOptimistic

rst.Source = "SELECT * FROM yourTable  "
rst.Open



rst.Close
cnn.Close

Set rst = Nothing
Set cnn = Nothing

Open in new window

0
 

Author Comment

by:RDLFC
ID: 33552606
thanks guys for your input, but I used the article at the site below and found it to be very helpful.

http://support.microsoft.com/kb/892490
0
 

Author Closing Comment

by:RDLFC
ID: 33552611
The comments assisted me in gathering an understanding but the article assisted in implementing the DNS less connection.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

728 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