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 July 12th, 2007, 07:30 PM
Authorized User
 
Join Date: Apr 2007
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default Vba to Change Pass Through Query Connection

I have some queries which are saved queries, yet sometimes I want to change the ODBC Connection String without having to manually open each of the queries in design mode to change the string. I have been trying to execute this through a Vba module. Below is an example what I have so far, but am struggling with the call to the object and changing its ODBC Connection property.

---------------------------------------------
Option Compare Database

Sub DbPointer()

Dim dbs As Database
Dim qrySNJobs As QueryDef

Set dbs = CurrentDb
Set qryPnetJobs = dbs.CreateQueryDef


qryPnetJobs.Connect????:( = ODBC;DSN=PalmSprings-PlantNetDb;DATABASE=PlantNet;Trusted_Connection=Ye s

End Sub

Any ideas on where I am going wrong would be appreciated tremendously.

Coby.

 
Old April 25th, 2011, 09:12 AM
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using VBA to update pass through query ODBC Connection string

Original Code:

Code:
Option Compare Database

Sub DbPointer()

Dim dbs As Database
Dim qrySNJobs As QueryDef

Set dbs = CurrentDb
Set qryPnetJobs = dbs.CreateQueryDef


qryPnetJobs.Connect????:( = ODBC;DSN=PalmSprings-PlantNetDb;DATABASE=PlantNet;Trusted_Connection=Ye s

End Sub
Updated code

The QueryDef connect property is expecting a string value that must be a string variable or text surrounded by quotes

Code:
Option Compare Database

Sub DbPointer()

Dim dbs As Database
Dim qrySNJobs As QueryDef

Set dbs = CurrentDb
Set qryPnetJobs = dbs.CreateQueryDef


qryPnetJobs.Connect = "ODBC;DSN=PalmSprings-PlantNetDb;DATABASE=PlantNet;Trusted_Connection=Yes"

End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Form Code with VBA emt_101 Access VBA 2 October 17th, 2008 11:45 AM
Change database connection song Visual Basic 2005 Basics 4 November 30th, 2007 01:22 AM
Change tbl permissions using VBA feets Access VBA 1 October 12th, 2007 01:19 AM
Change in connection string x_ray Classic ASP Basics 2 February 21st, 2006 05:10 PM
Pass-Through Query Optimization redrobot5050 Access VBA 3 June 18th, 2004 01:25 AM





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