Make your own free website on Tripod.com

Form

Private Sub Command1_Click() UserControl11.ver = Not (UserControl11.ver) End Sub Private Sub Command2_Click() UserControl11.Habil = Not (UserControl11.Habil) End Sub Private Sub Command3_Click() UserControl11.limpiar End Sub Private Sub UserControl11_totales(TR As Variant, RA As Variant) Form1.Caption = "Total de Clientes: " & TR & " Reg. actual: " & RA End Sub

Modulo

Public DB As Database Dim QDC As QueryDef Dim QDT As QueryDef Dim QDZ As QueryDef Public RSC As Recordset Public RST As Recordset Public RSZ As Recordset Sub ArmaRecordset(quien As String, sqlx As String) Set DB = OpenDatabase(App.Path & "\bd1.mdb") quien = UCase(quien) If quien = "C" Then Set QDC = DB.CreateQueryDef("", sqlx) Set RSC = QDC.OpenRecordset ElseIf quien = "T" Then Set QDT = DB.CreateQueryDef("", sqlx) Set RST = QDT.OpenRecordset ElseIf quien = "Z" Then Set QDZ = DB.CreateQueryDef("", sqlx) Set RSZ = QDZ.OpenRecordset End If End Sub Sub MuestraRecordset(ByVal querecordset As Recordset, quegrilla As Control) quegrilla.Rows = 1 If querecordset.RecordCount > 0 Then querecordset.MoveFirst Do While Not (querecordset.EOF) quegrilla.AddItem "" For x = 1 To quegrilla.Cols - 1 quegrilla.TextMatrix(quegrilla.Rows - 1, x) = querecordset.Fields(x - 1) Next x querecordset.MoveNext Loop End If End Sub Sub ArmaGrilla(Titulo, Ancho, quegrilla As Control) quegrilla.Rows = 1 quegrilla.Cols = UBound(Titulo) + 1 tot = 0 For x = 0 To quegrilla.Cols - 1 quegrilla.TextMatrix(0, x) = Titulo(x) quegrilla.ColWidth(x) = Ancho(x) tot = tot + Ancho(x) Next quegrilla.Width = tot + 400 End Sub

User Control

Public esalta As Boolean Public Event totales(TR, RA) Public VVer As Boolean Public VHabil As Boolean Sub alta() Call Command1_Click End Sub Sub bajas() Call Command2_Click End Sub Sub modificar() Call Command3_Click End Sub Sub consulta() Call Command4_Click End Sub Sub guardar() Call Command5_Click End Sub Property Get ver() As Boolean ver = VVer Text1.Visible = VVer Text2.Visible = VVer End Property Property Let ver(xxx As Boolean) VVer = xxx PropertyChanged ver End Property Property Get Habil() As Boolean Habil = VHabil Text1.Enabled = VHabil Text2.Enabled = VHabil End Property Property Let Habil(xxx As Boolean) VHabil = xxx PropertyChanged Habil End Property Sub actzona() If RST.RecordCount > 0 And Not (Data1.Recordset.EOF) Then Call ArmaRecordset("z", "select * from zona where caracteristica='" & Mid(Data1.Recordset.Fields(0), 1, 4) & "'") Text3 = RSZ.Fields(1) Else Text3 = "" End If End Sub Sub ACTUALIDBGRID() Call ArmaRecordset("T", "SELECT * FROM TELEFONO WHERE CODCLI='" & Text1 & "'") Set Data1.Recordset = RST End Sub Sub muestratexto() Text1 = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1) Text2 = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 2) RaiseEvent totales(MSFlexGrid1.Rows - 1, MSFlexGrid1.Row) End Sub Private Sub Command1_Click() Text1 = "" Text2 = "" esalta = True End Sub Private Sub Command2_Click() RSC.FindFirst "codigo='" & InputBox("Ingrese Código:") & "'" If RSC.NoMatch Then MsgBox ("no esta") Else DB.Execute "DELETE * FROM TELEFONO WHERE CODCLI='" & RSC.Fields(0) & "'" TEMP = RSC.Fields(0) DB.Execute "DELETE * FROM CLIENTE WHERE CODIGO='" & TEMP & "'" Call ArmaRecordset("C", "select * from cliente") Call MuestraRecordset(RSC, UserControl.MSFlexGrid1) RSC.MoveFirst Call muestratexto Call ACTUALIDBGRID End If End Sub Private Sub Command3_Click() RSC.FindFirst "codigo='" & InputBox("Ingrese Código:") & "'" If RSC.NoMatch Then MsgBox ("no esta") Else Text1 = RSC.Fields(0) Text2 = RSC.Fields(1) MSFlexGrid1.Row = RSC.AbsolutePosition + 1 Text1.Enabled = False esalta = False End If End Sub Private Sub Command4_Click() RSC.FindFirst "codigo='" & InputBox("Ingrese Código:") & "'" If RSC.NoMatch Then MsgBox ("no esta") Else Text1 = RSC.Fields(0) Text2 = RSC.Fields(1) MSFlexGrid1.Row = RSC.AbsolutePosition + 1 End If End Sub Private Sub Command5_Click() If esalta Then DB.Execute "insert into cliente (codigo,descripcion) values ('" & Text1 & "','" & Text2 & "')" Call ArmaRecordset("C", "select * from cliente") Call MuestraRecordset(RSC, UserControl.MSFlexGrid1) RSC.MoveLast Call muestratexto Call ACTUALIDBGRID Else DB.Execute "UPDATE CLIENTE SET DESCRIPCION='" & Text2 & "' WHERE CODIGO='" & Text1 & "'" TEMP = Text1 Call ArmaRecordset("C", "select * from cliente") Call MuestraRecordset(RSC, UserControl.MSFlexGrid1) RSC.FindFirst "CODIGO='" & TEMP & "'" MSFlexGrid1.Row = RSC.AbsolutePosition + 1 Call muestratexto Call ACTUALIDBGRID Text1.Enabled = True End If End Sub Private Sub Data1_Reposition() Call actzona End Sub Private Sub MSFlexGrid1_LeaveCell() MSFlexGrid1.CellBackColor = QBColor(15) End Sub Private Sub MSFlexGrid1_RowColChange() MSFlexGrid1.Col = 1 MSFlexGrid1.ColSel = 2 MSFlexGrid1.CellBackColor = QBColor(7) MSFlexGrid1.Col = 1 Call muestratexto Call ACTUALIDBGRID End Sub Private Sub Text4_Change() Call ArmaRecordset("C", "select * from cliente where descripcion like '" & Text4 & "*'") If RSC.RecordCount > 0 Then Call MuestraRecordset(RSC, UserControl.MSFlexGrid1) Call muestratexto Call ACTUALIDBGRID Call actzona End If End Sub Private Sub UserControl_Initialize() tit = Array("", "Código", "Descripción") anch = Array("400", "800", "1500") Call ArmaGrilla(tit, anch, UserControl.MSFlexGrid1) Call ArmaRecordset("C", "select * from cliente") Call MuestraRecordset(RSC, UserControl.MSFlexGrid1) Call muestratexto Call ACTUALIDBGRID Call actzona esalta = True End Sub Private Sub UserControl_Show() RaiseEvent totales(MSFlexGrid1.Rows - 1, MSFlexGrid1.Row) End Sub