Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 5th, 2004, 10:58 PM
Registered User
 
Join Date: Mar 2004
Location: Hobart, Tasmania, Australia.
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 ?


__________________



Reply With Quote
  #2 (permalink)  
Old April 7th, 2004, 11:11 AM
Registered User
 
Join Date: Apr 2004
Location: Houston, TX, USA.
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.
Reply With Quote
  #3 (permalink)  
Old April 7th, 2004, 06:19 PM
Registered User
 
Join Date: Mar 2004
Location: Hobart, Tasmania, Australia.
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 ?

Reply With Quote
  #4 (permalink)  
Old April 24th, 2004, 12:52 PM
Registered User
 
Join Date: Apr 2004
Location: , , .
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. devlinhyostler@hotmail.com

Reply With Quote
  #5 (permalink)  
Old April 24th, 2004, 12:53 PM
Registered User
 
Join Date: Apr 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

whoops, that should be
devlinhostler@hotmail.com

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:19 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.