Modulo


Public DB As Database
Dim QD1 As QueryDef
Public RS1 As Recordset
Sub armagrilla()
    With Form1.MSFlexGrid1
        tit = Array("", "Codigo", "Descripcion", "Tope", "Fecha", "Observaciones")
        ancho = Array(400, 500, 1000, 1000, 800, 1500)
        tot = 0
        
        .Rows = 1
        .Cols = UBound(tit) + 1
        For X = 0 To UBound(tit)
            .TextMatrix(0, X) = tit(X)
            .ColWidth(X) = ancho(X)
            tot = tot + ancho(X)
        Next
            .Width = tot + 400
        
    End With
End Sub

Sub armarecordset()
    Set DB = OpenDatabase(App.Path & "\bd1.mdb")
    Set QD1 = DB.CreateQueryDef("", "select * from TablaCliente")
    Set RS1 = QD1.OpenRecordset
End Sub
Sub muestrarecordset()
    Form1.MSFlexGrid1.Rows = 1
    If RS1.RecordCount > 0 Then
        RS1.MoveFirst
            Do While Not (RS1.EOF)
                Form1.MSFlexGrid1.AddItem ""
                For X = 1 To Form1.MSFlexGrid1.Cols - 1
                    Form1.MSFlexGrid1.TextMatrix(Form1.MSFlexGrid1.Rows - 1, X) = RS1.Fields(X - 1)
                Next
                    RS1.MoveNext
            Loop
            RS1.MoveFirst
    End If
End Sub

Sub cargatexto()
    For X = 0 To Form1.Text1.UBound
        Form1.Text1(X) = Form1.MSFlexGrid1.TextMatrix(Form1.MSFlexGrid1.Row, X + 1)
    Next
End Sub




Form



Private Sub Command1_Click()
    RS1.MoveNext
If RS1.EOF Then
    RS1.MoveLast
End If
Form1.MSFlexGrid1.Row = RS1.AbsolutePosition + 1
End Sub

Private Sub Command10_Click()
    Set QD1 = DB.CreateQueryDef("", "select * from TablaCliente where CliCodigo >=" & Text2 & " and CliCodigo <= " & Text3)
    Set RS1 = QD1.OpenRecordset
    Call muestrarecordset
    MSFlexGrid1.Col = MSFlexGrid1.Col + 1
End Sub

Private Sub Command11_Click()
    Set QD1 = DB.CreateQueryDef("", "select * from TablaCliente where CliDescripcion > '" & Trim(Text4) & "' and CliDescripcion < '" & Trim(Text5) & "'")
    Set RS1 = QD1.OpenRecordset
    Call muestrarecordset
    MSFlexGrid1.Col = MSFlexGrid1.Col + 1
End Sub

Private Sub Command12_Click()
    Set QD1 = DB.CreateQueryDef("", "select * from TablaCliente order by CliCodigo ")
    Set RS1 = QD1.OpenRecordset
    Call muestrarecordset
End Sub

Private Sub Command13_Click()
Set QD1 = DB.CreateQueryDef("", "select * from TablaCliente order by CliDescripcion ")
    Set RS1 = QD1.OpenRecordset
    Call muestrarecordset
End Sub

Private Sub Command2_Click()

    RS1.MovePrevious
If RS1.BOF Then
    RS1.MoveLast
End If
Form1.MSFlexGrid1.Row = RS1.AbsolutePosition + 1

End Sub

Private Sub Command3_Click()
RS1.MoveFirst
Form1.MSFlexGrid1.Row = RS1.AbsolutePosition + 1

End Sub

Private Sub Command4_Click()
RS1.MoveLast
Form1.MSFlexGrid1.Row = RS1.AbsolutePosition + 1

End Sub

Private Sub Command5_Click()
    DB.Execute "delete * from TablaCliente where Clicodigo =" & Text1(0)
    Call armarecordset
    Call muestrarecordset
End Sub

Private Sub Command6_Click()
    For Each X In Text1
        X.Text = ""
    Next
    Text1(0).SetFocus
End Sub

Private Sub Command7_Click()

DB.Execute " INSERT INTO TablaCliente (CliCodigo,CliDescripcion,CliTopeCredito,CliFechaIngreso,CliObservaciones) VALUES (" & Text1(0) & ",'" & Text1(1) & "'," & Text1(2) & "," & Text1(3) & ",'" & Text1(4) & "');"
Call armarecordset
Call muestrarecordset
End Sub

Private Sub Command8_Click()
Dim val As Integer
val = InputBox("")
RS1.FindFirst "CliCodigo =" & val
If RS1.NoMatch Then
    MsgBox ("Codigo no valido...")
Else
    MSFlexGrid1.Row = RS1.AbsolutePosition + 1
End If
End Sub

Private Sub Command9_Click()
DB.Execute "UPDATE TablaCliente SET CliDescripcion = '" & Text1(1) & "',CliTopeCredito = " & Text1(2) & ",CliFechaIngreso = " & Text1(3) & ", CliObservaciones = '" & Text1(4) & "'  where CliCodigo = " & Text1(0) & ";"
Call armarecordset
Call muestrarecordset
    

End Sub

Private Sub Form_Load()
Call armagrilla
Call armarecordset
Call muestrarecordset
Call cargatexto
End Sub

Private Sub MSFlexGrid1_RowColChange()
    Call cargatexto
End Sub
Make your own free website on Tripod.com