Visual Basic para Aplicaciones - Actualizar registros con un formulario en VBA

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil

Actualizar registros con un formulario en VBA

Publicado por Andres (3 intervenciones) el 12/04/2017 05:36:24
Hola A todos

Me pueden ayudar verificando este codigo...

Los ambiento la idea es buscar mediante un codigo ingresado en el formulario la informacion relacionada a ese registro para modificarla


utilizo la depuracion y lo que identifico es que en la linea que resalto , nunca encuentra un valor ingresado en el textbox igual al del registro en la base de datos por lo que no me trae los datos existentes a los demas textbox


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Private Sub TextBox_COD_REFM_Change()
    Dim dato As Variant
    Dim fila As Integer
    Dim final As Integer
 
        If TextBox_COD_REFM = Empty Then
            Me.ComboBox_LIDER_REFM = Empty
            Me.ComboBox_SUPER_REFM = Empty
            Me.TextBox_NOMBRE_REFM = Empty
            Me.Label_SELECT_DOC_REFM = Empty
            Me.TextBox_NUMERO_DOCUMENTO_REFM = Empty
            Me.TextBox_DIRECCION_REFM = Empty
            Me.TextBox_TEL_CEL_REFM = Empty
            Me.TextBox_CORREO_REFM = Empty
        End If
 
        For fila = 7 To 1000
            If Hoja1.Cells(fila, 1) = Empty Then
                final = fila - 1
                Exit For
            End If
        Next
 
    dato = TextBox_COD_REFM.Value
 
 
        For fila = 7 To final
            If dato = "" Then
                Exit Sub
            Else
                If dato = Hoja1.Cells(fila, 1) Then
                Me.ComboBox_LIDER_REFM = Hoja1.Cells(fila, 4)
                Me.ComboBox_SUPER_REFM = Hoja1.Cells(fila, 3)
                Me.TextBox_NOMBRE_REFM = Hoja1.Cells(fila, 5)
                Me.Label_SELECT_DOC_REFM = Hoja1.Cells(fila, 6)
                Me.TextBox_NUMERO_DOCUMENTO_REFM = Hoja1.Cells(fila, 7)
                Me.TextBox_DIRECCION_REFM = Hoja1.Cells(fila, 8)
                Me.TextBox_TEL_CEL_REFM = Hoja1.Cells(fila, 9)
                Me.TextBox_CORREO_REFM = Hoja1.Cells(fila, 10)
                Exit For
            End If
        End If
        Next
 
End Sub

Captura-2
Captura-1
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Actualizar registros con un formulario en VBA

Publicado por JuanC (565 intervenciones) el 12/04/2017 12:22:12
hice pequeños cambios, aún así no estoy seguro si funcionará, necesitaría el libro para depurar...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Private Sub TextBox_COD_REFM_Change()
    Dim dato$
    Dim fila&, final&
 
    dato = VBA.Trim(TextBox_COD_REFM.Text)
    If dato = "" Then
       ComboBox_LIDER_REFM = Empty
       ComboBox_SUPER_REFM = Empty
       TextBox_NOMBRE_REFM = Empty
       Label_SELECT_DOC_REFM = Empty
       TextBox_NUMERO_DOCUMENTO_REFM = Empty
       TextBox_DIRECCION_REFM = Empty
       TextBox_TEL_CEL_REFM = Empty
       TextBox_CORREO_REFM = Empty
       Exit Sub
    End If
 
       For fila = 7 To 1000
            If Hoja1.Cells(fila, 1) = Empty Then
                final = fila - 1
                Exit For
            End If
        Next
 
        For fila = 7 To final
            If dato = VBA.Trim(CStr(Hoja1.Cells(fila, 1).Value)) Then
                ComboBox_LIDER_REFM = Hoja1.Cells(fila, 4)
                ComboBox_SUPER_REFM = Hoja1.Cells(fila, 3)
                TextBox_NOMBRE_REFM = Hoja1.Cells(fila, 5)
                Label_SELECT_DOC_REFM = Hoja1.Cells(fila, 6)
                TextBox_NUMERO_DOCUMENTO_REFM = Hoja1.Cells(fila, 7)
                TextBox_DIRECCION_REFM = Hoja1.Cells(fila, 8)
                TextBox_TEL_CEL_REFM = Hoja1.Cells(fila, 9)
                TextBox_CORREO_REFM = Hoja1.Cells(fila, 10)
                Exit For
            End If
        Next
 
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Actualizar registros con un formulario en VBA

Publicado por Andres (3 intervenciones) el 12/04/2017 18:32:35
Muchas Gracias JuanC,

con tu aporte el problema quedo resuelto.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar