Sub LlenarProductosGrid()
Dim Sql As String
Dim Filtro As String
Dim Ordenar As String
Dim Columnas As Integer
Dim Op As Integer
Dim Ord As Integer
Op = cmdTipoBusqueda.ListIndex
Filtro = ""
Select Case Op
Case 0:
Filtro = " tblProductos.NombrePro Like '%" & txtFiltro & "%'"
Case 1:
Filtro = " tblProductos.CodigoPro Like '%" & txtFiltro & "%'"
Case 2:
Filtro = " tblCategorias.NombreCategoria Like '%" & txtFiltro & "%'"
Case 3:
Filtro = " tblProveedores.NombreEmpresaPro Like '%" & txtFiltro & "%'"
Case 4:
Filtro = " tblProductos.PVenta1Pro >= " & txtFiltro
Case 5:
Filtro = " tblProductos.PVenta1Pro <= " & txtFiltro
End Select
Ord = cmdOrdenarpor.ListIndex
Select Case Ord
Case 0:
Ordenar = " tblProductos.NombrePro ASC "
Case 1:
Ordenar = " tblProductos.CodigoPro ASC "
End Select
'Sql, para esto se debe coger datos de Access de la Consulta rápida
Sql = "SELECT tblProductos.IdProducto, tblProductos.CodigoPro, tblProductos.NombrePro, tblProductos.ExistPro, tblProductos.ExistMinPro, Format(tblProductos.PCostoPro, 'currency'), Format(tblProductos.PVenta1Pro, 'currency'), Format(tblProductos.PVenta2Pro, 'currency'), Format(tblProductos.PVenta3Pro, 'currency'), Format(tblProductos.PMinimoPro, 'currency'), tblCategorias.NombreCategoria, tblProveedores.NombreEmpresaPro " _
& " FROM (tblProductos INNER JOIN tblCategorias ON tblProductos.IdCategoria = tblCategorias.Idcategoria) INNER JOIN tblProveedores ON tblProductos.IdProveedor = tblProveedores.IdProveedor;" 'WHERE " & Filtro & " order by " & Ordenar
'Sql = "SELECT tblProductos.IdProducto, tblProductos.CodigoPro, tblProductos.NombrePro, tblProductos.NombreCortoPro, tblProductos.ExistPro, tblProductos.ExistMinPro, Format(tblProductos.PCostoPro, 'currency'), Format(tblProductos.PVenta1Pro,'currency'), Format(tblProductos.PVenta2Pro,'currency'), Format(tblProductos.PVenta3Pro,'currency'), Format(tblProductos.PMinimoPro,'currency'), tblCategorias.NombreCategoria, tblProveedores.NombreEmpresaPro " _
' & "FROM tblProveedores INNER JOIN (tblCategorias INNER JOIN tblProductos ON tblCategorias.Idcategoria = tblProductos.IdCategorias) ON tblProveedores.IdProveedor = tblProductos.IdProveedor WHERE '" & txtFiltro & "' order by " & Ordenar
' Sql = "SELECT tblProductos.IdProducto, tblProductos.CodigoPro, tblProductos.NombrePro, tblProductos.NombreCortoPro, tblProductos.ExistPro, tblProductos.ExistMinPro, Format(tblProductos.PCostoPro,'currency'), Format(tblProductos.PVenta1Pro,'currency'), Format(tblProductos.PVenta2Pro,'currency'), Format(tblProductos.PVenta3Pro,'currency'), Format(tblProductos.PMinimoPro,'currency'), tblCategorias.NombreCategoria, tblProveedores.NombreEmpresaPro " _
' & " FROM tblCategorias, tblProductos INNER JOIN tblProveedores ON tblProductos.IdProveedor = tblProveedores.IdProveedor WHERE " & Filtro & " order by " & Ordenar
' & " FROM (tblProductos INNER JOIN tblCategorias ON tblProductos.IdCategoria = tblCategorias.Idcategoria) INNER JOIN tblProveedores ON tblProductos.IdProveedor = tblProveedores.IdProveedor WHERE " & Filtro & " order by " & Ordenar
Columnas = 12
Call LlenarGrid(msGrid, Sql, Columnas)
'Se debe formar siempre matrices iguales ej, 12x12
msGrid.ColWidth(0) = 0 'índice de la columna, no es necesario (cero)
msGrid.ColWidth(1) = 0 'Id del Producto, no es necesario (cero)
msGrid.ColWidth(2) = 1800
msGrid.ColWidth(3) = 4000
msGrid.ColWidth(4) = 1100
msGrid.ColWidth(5) = 1100
msGrid.ColWidth(6) = 1500
msGrid.ColWidth(7) = 1500
msGrid.ColWidth(8) = 1500
msGrid.ColWidth(9) = 1500
msGrid.ColWidth(10) = 2000
msGrid.ColWidth(11) = 2000
msGrid.ColWidth(12) = 4000
'Esta lineas permite solo escoger datos requeridos de la Db access
msGrid.TextMatrix(0, 2) = "Código"
msGrid.TextMatrix(0, 3) = "Nombre Producto"
msGrid.TextMatrix(0, 4) = "Exist"
msGrid.TextMatrix(0, 5) = "Exis. Min"
msGrid.TextMatrix(0, 6) = "P. Costo"
msGrid.TextMatrix(0, 7) = "P. Venta 1"
msGrid.TextMatrix(0, 8) = "P. Venta 2"
msGrid.TextMatrix(0, 9) = "P. Venta 3"
msGrid.TextMatrix(0, 10) = "P. Mínima"
msGrid.TextMatrix(0, 11) = "Categoría"
msGrid.TextMatrix(0, 12) = "Proveedor"
msGrid.ColAlignment(4) = flexAlignCenterCenter 'Centrar los datos
msGrid.ColAlignment(5) = flexAlignCenterCenter
Dim PrecioCost1 As Integer
SumTotal = 0
For Fila = 1 To msGrid.Rows - 1
Exist = msGrid.TextMatrix(Fila, 4)
PrecioCost = CCur(msGrid.TextMatrix(Fila, 6)) 'CCur
SumaTotal = SumaTotal + (Exist * PrecioCost)
If Exist <= 0 Then
msGrid.Row = Fila
msGrid.Col = 4
msGrid.CellBackColor = &HC0& 'color de fondo
msGrid.CellForeColor = &H80000005 'color de la letra
End If
Next Fila
lblNumArticulos.Caption = msGrid.Rows - 1
txtTotalLista.Text = Format(SumaTotal, "currency")
End Sub