Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default EXCEL AND ODBC AND QUERY

Hi there,

I have an Excel file 2002 format that currently has a
query extracting data from a mainframe file using an ODBC
Connection. All works fine. Now time to progress to the
next level, and have some parameters, to limit the data
coming from the mainframe file.

I have a field on a sheet called "tables" that contains a
department code "001".

Q1. How do I limit the ODBC connection to obtaining only
those records with the department code "001", without
hard coding that into the query (the department may
change).

Q2. How can I programatically create an ODBC connection
to the mainframe table without having to configure the
ODBC driver on each user's PC ?

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default EXCEL AND ODBC AND QUERY

Hi Gary B,

I have an Excel file 2002 format that currently has a
query extracting data from a mainframe file using an ODBC
Connection. All works fine. Now time to progress to the
next level, and have some parameters, to limit the data
coming from the mainframe file.

I have a field on a sheet called "tables" that contains a
department code "001".

Q1. How do I limit the ODBC connection to obtaining only
those records with the department code "001", without
hard coding that into the query (the department may
change).


Hopefully this will get you started

Sub UpdateExternalQuery()
Dim str_SQ1 As String
Dim str_SQ2 As String
Dim str_deptCode As String

' str_deptCode is parameter in query
str_deptCode = "001"

' build a SQL statement
str_SQ1 = "SELECT myqry.* FROM mydb.dbo.myqry myqry "

str_SQ2 = "WHERE myqry.dept_code = '" & str_deptCode& "' "

' handle missing parameters by changing the SQL string
If str_deptCode = "" Then
str_SQ2 = ""
End If

' data_dump is the named range of the query table in Excel
With Range("data_dump").QueryTable
.Connection = _
"ODBC;DSN=myDSN;UID=login;PWD=password;APP=Microso ft® Query;DATABASE=mydb"
.CommandText = Array(str_SQ1, str_SQ2)
.Refresh BackgroundQuery:=False
End With

End Sub

Q2. How can I programatically create an ODBC connection
to the mainframe table without having to configure the
ODBC driver on each user's PC ?

Thanks in advance.


You will notice that the above example uses a predefined DSN. You can use a
file DSN and distribute it with your application. Or you can ask this group
to see if anyone can build DSN connections programmatically :)


--
Ed Ferrero
http://edferrero.m6.net


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
odbc error on Excel query into database flowry Excel Discussion (Misc queries) 2 November 6th 08 09:26 PM
Changing ODBC data source for a query embedded in Excel Matt Colegrove Excel Discussion (Misc queries) 4 June 15th 07 01:04 AM
how to access databases from excel using ms query and odbc? Nabin Excel Discussion (Misc queries) 0 October 11th 06 07:32 AM
msquery odbc -- excel repeats query on return [email protected] Excel Discussion (Misc queries) 0 April 3rd 06 06:22 PM
Excel query via ODBC cuts values escelinen Excel Discussion (Misc queries) 1 January 23rd 06 05:40 AM


All times are GMT +1. The time now is 10:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"