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
| 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 August 15th, 2007, 09:22 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
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


Reply With Quote
  #2 (permalink)  
Old August 16th, 2007, 06:34 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
  #3 (permalink)  
Old August 16th, 2007, 06:36 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
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
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



All times are GMT -4. The time now is 03:00 PM.


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