Option Explicit
Dim RsSearch As New Recordset
Dim inv As ListItem

Public Function SearchFucn(SQLString As String, combovalue As String)
Set RsSearch = Nothing
If DataEnvironment1.Connection1.State = adStateClosed Then DataEnvironment1.Connection1.Open
If RsSearch.State <> adStateClosed Then RsSearch.Close
With RsSearch
       .ActiveConnection = DataEnvironment1.Connection1
       .Open SQLString
End With
If RsSearch.RecordCount = 0 Then
  MsgBox "No record found"
Else
    FillSearchgrid combovalue
End If
End Function

Public Function FillSearchgrid(combovalue As String)
frmsearch.DataGrid1.ClearFields
Select Case combovalue
Case "Item Code"
    With frmsearch.DataGrid1.Columns
               .Add(0).Caption = "Item Code"
          End With
   Set frmsearch.DataGrid1.DataSource = RsSearch
 
Case "Item Name"
    With frmsearch.DataGrid1.Columns
               .Add(0).Caption = "Item name"
          End With
   Set frmsearch.DataGrid1.DataSource = RsSearch
 
Case "Brand Name"
    With frmsearch.DataGrid1.Columns
               .Add(0).Caption = "Brand name"
          End With
   Set frmsearch.DataGrid1.DataSource = RsSearch
 
 
Case "Employee Id"
    With frmsearch.DataGrid1.Columns
               .Add(0).Caption = "Employee Id"
          End With
   Set frmsearch.DataGrid1.DataSource = RsSearch
 
  
Case "Employee First Name"
    With frmsearch.DataGrid1.Columns
            .Add(0).Caption = "Employee First Name"
            End With
    Set frmsearch.DataGrid1.DataSource = RsSearch
    
Case "Employee Surname"
    With frmsearch.DataGrid1.Columns
            .Add(0).Caption = "Employee Surname"
            End With
    Set frmsearch.DataGrid1.DataSource = RsSearch

Case "Supplier Id"
    With frmsearch.DataGrid1.Columns
            .Add(0).Caption = "Supplier Id"
            End With
    Set frmsearch.DataGrid1.DataSource = RsSearch

Case "Company Name"
    With frmfind.searchgrid.Columns
            .Add(0).Caption = "Company Name"
            End With
  Set frmsearch.DataGrid1.DataSource = RsSearch

End Select
End Function


Public Function SearchFunction(SQLString As String, textvalue As String)
Set RsSearch = Nothing
If DataEnvironment1.Connection1.State = adStateClosed Then DataEnvironment1.Connection1.Open
If RsSearch.State <> adStateClosed Then RsSearch.Close
With RsSearch
        .ActiveConnection = DataEnvironment1.Connection1
        .Open SQLString
End With
If RsSearch.RecordCount = 0 Then
   MsgBox "No record found"
Else
    ' listfill textvalue
End If
End Function

Where did your error occur in the above code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.