'************************************************************** ' Name: RefreshGrid_grdLookup ' Purpose: Refreshes the data grid ' Assumptions: none. ' Effects: instantiate/create: ' SQL Server Native database connection object ' ADO Recordset object ' ADO Command object ' Parameter object ' Executes the ADO Command Object returning an ADO recordset. ' The ADO recordset is used to refresh the grid ' Inputs: ' The Grid Control ' TheUser's typed in search value. ' Returns: None ' Dev Notes: EB: The Seachstring should be passed in as a variable. '************************************************************** Sub RefreshGrid_grdLookup (ByRef theGrid, ByVal theUserInput) Application.Debug.Writeline "59 20. RefreshGrid_grdLookup BEGIN "
Dim strSQL Dim myNativeConn Dim myRS
' ADO DB Command object Dim objCommand
' Parameter(s) for the Command object Dim objParam
' instantiate native connection object, opened. ' SLXDatabaseSupport_GetNativeConnection(ByRef TheConn) Call SLXDatabaseSupport_GetNativeConnection( myNativeConn )
' Get a recordset 'SUB SLXDatabaseSupport_GetADORecordSet (ByRef TheRS) Call SLXDatabaseSupport_GetADORecordSet (myRS) ' Add Fields to the recordset as needed myRS.Fields.Append "OPPORTUNITYID", adChar, 12
' Declare the Select statement, identifying parameters with ? strSQL = "SELECT A1.OPPORTUNITYID" & _ " , A1.DESCRIPTION" & _ " , A2.ACCOUNT A2_ACCOUNT" & _ " , A1.SALESPOTENTIAL" & _ " FROM sysdba.OPPORTUNITY A1 WITH(NOLOCK)" & _ " INNER JOIN ACCOUNT A2 WITH(NOLOCK) ON (A2.ACCOUNTID=A1.ACCOUNTID)" & _ " WHERE A1.OPPORTUNITYID LIKE ?" & _ " ORDER BY A1.OPPORTUNITYID "
' set up command object Set objCommand = createObject("ADODB.Command") objCommand.activeConnection = myNativeConn objCommand.commandText = strSQL
' 1 line statement, not for general use 'objCommand.parameters.append(objCommand.createParameter("", adVarChar, adParamInput, 255, theUserInput))
Set objParam = createObject("ADODB.Parameter") With objParam .Type = adVarChar .Size = 100 .Direction = adParamInput .Value = theUserInput End With
'Append the parameter(s) to command object objCommand.Parameters.Append objParam
' Execute the command and store the results in a recordset myRS.Open objCommand
' load / refresh the data grid. set thegrid = myRS 'Call GridCommon_RefreshGridByRS (theGrid, myRS)
' housekeeping. Set objCommand = Nothing ' Set objParam = Nothing Set myNativeConn = Nothing Set myRS = Nothing ' DO NOT CLOSE the recordset! Simply set this reference to nothing. End Sub <\pre>
|