#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default sql.request

I need to do a select from a mysql db so that a cells are updated by the information inserted into neighboring cells. I have looked around, and it seems like i need to use sql.request, but it is not available. I am using excel 2003, and xlodbc is not available. I tried the 2002 version, but it won't install. It gives the error that office xp or 2002 is not found. Can someone help? I'd also appreciate it if anyone could post other methods of doing what I'm trying to do.

e.g. i need to insert a job# in a1 and have a2 pull the job description from a database.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default sql.request

Can't help you as to how to get sql.request working, but
there are two other ways you could do this:

1) Use MSQuery: Data... Get External Data... New Database
Query. Choose your data source and then use MSQuery to
choose the specified field (job description) with criteria
based on your parameter (job #). Refer to Excel and
MSQuery help.

2) Using VBA, add a reference to Microsoft ActiveX Data
Objects Library and use ADO methods to write your own
(optimized) version of sql.request. Below is an example
(MIDAS is the name of the database I work with):

Public Function MIDASSQL(SELECTStr As String, _
FROMStr As String, _
WHEREStr As String) _
As Variant

'
' Function to execute a SQL query in MIDAS
' (NOTE: Only single value can be returned!)
'
' Possible error conditions:
' 1) Invalid SQL string - return an error code
' 2) No matching records - return the
string "NOT FOUND"
' 3) Multiple fields - return the
string "MULTIPLE FIELDS"
' 4) Multiple records - return the first record
'

On Error GoTo ERR

' Set up object variables for MIDAS connection and
records
Dim MIDAScn As ADODB.Connection
Dim MIDASrs As ADODB.Recordset

' Variables for the SQL string and the returned
value
Dim SQL As String
Dim MIDASData As Variant

' Variable to assign to MIDAS fields
Dim MIDAS1 As Variant

' Variable to count the number of records returned
Dim MRecords As Integer

MIDASData = ""
SQL = ""

'
' Set up the object variables for the ODBC
connection to the MIDAS database
'

Set MIDAScn = New ADODB.Connection
Set MIDASrn = New ADODB.Recordset

'
' Open the MIDAS connection. Note the data source
name, user ID and password
' will need to be changed here if there are ever
changes in MIDAS
'

MIDAScn.Open ("DSN=*Data Source Name*;UID=*User
ID*;PWD=*password*")

'
' Send SQL query to return the recordset matching
the specified parameters
'

SQL = "SELECT " & SELECTStr & " FROM " & FROMStr
& " WHERE " & WHEREStr

Set MIDASrs = MIDAScn.Execute(SQL)

'
' Check immdiately for and end of file (no records
found):
'

If MIDASrs.EOF Then

MIDAS1 = "NOT FOUND"

'
' Otherwise get the first corresponding result
value
'

Else

If MIDASrs.Fields.Count 1 Then

MIDAS1 = "MULTIPLE FIELDS"
Else

MIDAS1 = MIDASrs.Fields(0).Value

End If

End If

'
' Set the function return value:
'

MIDASSQL = MIDAS1

'
' Remember to close the connection and clear the
object variables
'

MIDAScn.Close
Set MIDASrs = Nothing
Set MIDAScn = Nothing

Exit Function

'
' Error handler:
'

ERR:

MIDASSQL = ERR.Number

If MIDASrs.State = adStateOpen Then MIDASrs.Close
If MIDAScn.State = adStateOpen Then MIDAScn.Close
Set MIDASrs = Nothing
Set MIDAScn = Nothing

End Function




-----Original Message-----
I need to do a select from a mysql db so that a cells are

updated by the information inserted into neighboring
cells. I have looked around, and it seems like i need to
use sql.request, but it is not available. I am using
excel 2003, and xlodbc is not available. I tried the 2002
version, but it won't install. It gives the error that
office xp or 2002 is not found. Can someone help? I'd
also appreciate it if anyone could post other methods of
doing what I'm trying to do.

e.g. i need to insert a job# in a1 and have a2 pull the

job description from a database.
.

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
If then request bpc Excel Worksheet Functions 1 September 22nd 09 06:35 PM
SQL.REQUEST SQL.REQUEST Excel Discussion (Misc queries) 0 November 12th 07 02:34 AM
SQL.REQUEST SQL.REQUEST Excel Discussion (Misc queries) 0 November 12th 07 02:33 AM
2nd request Christy[_2_] Excel Programming 0 October 1st 03 01:32 AM
sql.request Ivan Belal Excel Programming 1 September 18th 03 08:24 PM


All times are GMT +1. The time now is 05:10 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"