Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
If then request | Excel Worksheet Functions | |||
SQL.REQUEST | Excel Discussion (Misc queries) | |||
SQL.REQUEST | Excel Discussion (Misc queries) | |||
2nd request | Excel Programming | |||
sql.request | Excel Programming |