Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2004, 10:58 PM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to connect Access to diff databases


Using File>Connection in Access one can connect to database of choice. My application needs to be able to switch from local MSDE database to server-based Sqlserver database.

Can this be done via VBA ?

If not, can I distribute my Access application in any (secure) way that would enable a user to do this ?


__________________



 
Old April 7th, 2004, 11:11 AM
Registered User
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rexecampbell
Default

Use ADO to make your connection to either Access or SQL Server. This works great for VBA.

Dim MyDb, MyRec as Variant
Set MyDb = New ADODB.Connection
Set MyRec = New ADODB.Recordset

Then use the MyDb.Open to connect to your database of choice.
A good source for ADO connections is http://www.able-consulting.com/ADO_Conn.htm

From there you can open your recordset like so
MyRec.Open "SELECT * FROM Table WHERE Field = 'Condition'", MyDb, adOpenDynamic, adLockOptimistic, adCmdText

make sure to close your connections when done. I hope this helps.
 
Old April 7th, 2004, 06:19 PM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for that, but my need is to change the current connection - that referred to by:
CurrentProject.Connection
The connection established by File>Connection when in design mode in Access.
How to change this via VBA

I haven't got the syntax right. I tried:

strConn = "Provider=Microsoft OLE DB Provider for Sql Server;" & _
"Data Source=Sqldev;Initial Catalog=TestRig;" & _
"Persist Security Info=False; ;Integrated Security=SSPI;"
CurrentProject.Connection.Close
CurrentProject.Connection.Open (strConn)

and get the error:
Operation is not allowed when the object is open

CurrentProject.CloseConnection
gives the error:
6008. Microsoft Access encountered an error closing your connection


Any clues ?

 
Old April 24th, 2004, 12:52 PM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can't do it either, have trawled through msdn exhaustively to no avail. If you've found the answer please let me know. [email protected]

 
Old April 24th, 2004, 12:53 PM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

whoops, that should be
[email protected]






Similar Threads
Thread Thread Starter Forum Replies Last Post
Synch 2 access databases raguapk Pro VB 6 2 December 11th, 2007 11:27 PM
MySQL Connect DataBases!!! asadullah SQL Language 1 April 26th, 2007 12:54 AM
MS Access Databases dmoffice VB Databases Basics 1 October 10th, 2006 03:37 PM
Updating Access Databases rsm42 ASP.NET 1.0 and 1.1 Basics 11 September 11th, 2006 02:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.