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 August 15th, 2007, 09:22 AM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default create pass through query to connect to Sybase

Hi All,

I am a newbie in Access.
Using Access VBA, I am trying to create a Pass Through Query to connect to the Sybase Server so that I can show the user what the recordset looks like. I am having trouble creating the Connect String in the code.

I cannot create a DSN As then it will be machine dependent...in the sense every user who accesses the database(access) has to create a DSN in their own machine.

I created a DSN Less Connection using ADO to Connect to Sybase Server and I am able to read the records as follows:
****************************************
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql, constr, str As String

Set conn = New ADODB.Connection
constr = "Driver={SYBASE ASE ODBC Driver};NA=<x.x.x.x,portnumber>;Uid=USER;Pwd=PASS; "
conn.ConnectionString = constr
conn.Open

sql = "select column1, column2 from Table1";

Set rs = conn.Execute(sql)

While Not rs.EOF
  Debug.Print rs.Fields(0) & rs.fields(1)
  rs.MoveNext
Wend

    ' Cleanup
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
****************************************
The Above Code is working when creating a DSN Less Connection using ADO and fetching the recordset.

I want to create a pass though query so that I can open the query and execute it and display data to user.
****************************************
Dim db As DAO.Database
Dim qry As DAO.QueryDef
Dim rs As DAO.Recordset
Dim sql as string

On Error GoTo errBlock

Set db = CurrentDb

sql = "select column1,column2 from table1"

Set qry = db.CreateQueryDef("qryTemp", sql)

qry.Connect = "ODBC;Driver={SYBASE ASE ODBC Driver};NA=<x.x.x.x,portnumber>;UID=user;PWD=pass"

qry.sql = sql
qry.ReturnsRecords = True
Set rs = qry.OpenRecordset(dbOpenSnapshot)

MsgBox rs.RecordCount
DoCmd.OpenQuery "qryTemp"
****************************************
I am getting the error "Invalid connection String" when the qry.connect is executed.

Am I missing something here?

NOTE: I do not(should not) have any DSN created in my machine.

Please advise.

regards
mustang123


 
Old August 16th, 2007, 06:34 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   DAO is for Jet databases only. Why don't you use the ADO code in the previous section? In the DAO section, your DB is Current, and I don't think this will work with a remote database. Am I missing something that requires the change in the code? Anyway, DAO won't work. Is ADO not working?

   Normally I would create a View (in SQL Server) on the DBMS, and then just take the data from the server-side query since it is optimized by the server, and keeps record searching down on the server and data volume down on the wire. Can you do that? You can then pass parameters to that server-side query/view.

Did any of that help?

mmcdonal
 
Old August 16th, 2007, 06:36 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Also, you can add a module to create the DSN if it is not found on the machine, so the database supports itself. I can post code to show you how to check for it, and if not found, install it.



mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
create stored procedure+pass qry textbox Pradeep_6323 Struts 0 March 12th, 2008 02:03 AM
how to create a GUI that connect to sql server method Java GUI 1 April 15th, 2005 07:22 AM
howto create sybase dsn ? qwjunk Access 0 August 24th, 2004 09:46 AM
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.