Populate DataGrid based on a selected combo box value (1 Viewer)

dfuas

Registered User.
Local time
Today, 00:36
Joined
Jan 4, 2006
Messages
66
Hi,

How do I populate results on a datagrid based on the user I select from a combo box. I have a combo box with X number of users and want to show the results for a user A only.
I am filtering the results for each user based on option buttoms whether the job is finished, live, or all.
Right now I can display the results for all users regardless which one I select in the combo box.
This is really driving me crazy now, please help.
I have no much experience in this, so I will be gratefull.
Below is the code I am using for this.

Thanks

dfuas

Code:
CREATE PROCEDURE SP_CREQUEST_SEARCH 
AS


SELECT     R.RequestID, R.ShortDescription, RTRIM(U.FirstName) + ' ' +RTRIM(ISNULL(U.LastName, '')) AS 'User Name', 
	   D.Department, R.StartDate, R.EstimateDate, R.FinishDate, R.LastUpdate

FROM       Request R INNER JOIN
           Users U ON R.UserID = U.UserID INNER JOIN
           Department D ON U.DepartmentID = D.DepartmentID

Code:
Private Sub cmdSearch_Click()
    Dim cmd As ADODB.Command
    Dim rst As ADODB.Recordset
    Dim Temp$
    
    
    Set cmd = New ADODB.Command
    Set rst = New ADODB.Recordset
            
    OpenConn
    
    With cmd
        .ActiveConnection = cn
        .CommandType = adCmdStoredProc
        .CommandText = "VIEW_USERS_SORTED"
            
    End With
    
    CloseConn
    
        
    If Me.cboSearchFor.Text <> "" Then
        
        If Me.optSearchFor(0).Value = True And Me.optSearchCriteria(0).Value = True Then
        
            
            Temp$ = Me.cboSearchFor.Text
            
    With rst
        
      rst.Filter = Temp$
        
    End With
    
    
    Set rst = Nothing

    Call GetSearch
   
       
        End If
            
    
    End If
        
     
End Sub

Code:
Private Function GetSearch(Optional UserId As Integer)

    Dim cmd As ADODB.Command
    Dim rst As ADODB.Recordset

    Set cmd = New ADODB.Command
    Set rst = New ADODB.Recordset
    
    OpenConn
    
    With cmd
        .ActiveConnection = cn
        .CommandType = adCmdStoredProc
        .CommandText = "SP_CREQUEST_SEARCH"
                
        Set rst.DataSource = .Execute
        
        Set Me.grdSearch.DataSource = Nothing
        Set Me.grdSearch.DataSource = rst
        
        If Me.optSearchCriteria(0).Value = True And Me.optSearchFor(0).Value = True Then
            
            rst.Filter = ""
            rst.Filter = "FinishDate <=" & Date
        
        ElseIf Me.optSearchCriteria(1).Value And Me.optSearchFor(0).Value = True Then
        
            rst.Filter = ""
            'rst.Filter = ("FinishDate >=" & Date Or "EstimateDate >=" & Date & "'")
            rst.Filter = "EstimateDate >=" & Date
            rst.Filter = "FinishDate = NULL"
            rst.Filter = "EstimateDate = NULL"
            
        ElseIf Me.optSearchCriteria(2).Value And Me.optSearchFor(0).Value = True Then
            
            rst.Filter = ""
            rst.Filter = adFilterNone
            
        End If
        
             
    End With
    
    CloseConn

End Function
 

Users who are viewing this thread

Top Bottom