Access - un mismo evento para diferentes textbox

 
Vista:

un mismo evento para diferentes textbox

Publicado por yukis (15 intervenciones) el 26/08/2013 20:06:28
Tengo un formulario de control de asistencia mensual.
viene de una tabla con los campos 1M,1T,2M,2T,3M,3T.... hasta el 31m y 31t.
para rellenar el form con el mouse he puesto el siguiente codigo al evento al hacer click en el textbox:

Private Sub Ctl1T_Click()
If [1M] = 0 Then
[1M] = 1
Else
If [1M] = 1 Then
[1M] = 2
Else
If [1M] = 2 Then
[1M] = 0
End If
End If
End If

End Sub


hay alguna manera de hacer lo mismo sin escribir el mismo codigo en cada textbox?

muchas gracias
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
sin imagen de perfil

un mismo evento para diferentes textbox

Publicado por deneg_nhj (348 intervenciones) el 27/08/2013 19:37:38
Jukis,

Puedes intentar una solución como está.

Así la invocas.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Private Sub Ctl1T_Click()
   sbValidaVariosTxt  Ctl1T
End Sub
 
Private Sub Ctl2T_Click()
   sbValidaVariosTxt  Ctl2T
End Sub
 
Private Sub Ctl3T_Click()
   sbValidaVariosTxt  Ctl3T
End Sub
.
.
.




Y aquí está la rutina

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Sub sbValidaVariosTxt(xTxt As TextBox)
 
    If xTxt.Value = 0 Then
        xTxt.Value = 1
    Else
        If xTxt.Value = 1 Then
            xTxt.Value = 2
        Else
            If xTxt.Value = 2 Then
                xTxt.Value = 0
            End If
        End If
    End If
 
End Sub




Prueba y me dices si te funciona!

Saludos!

deneg_nhj
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

un mismo evento para diferentes textbox

Publicado por yukis (15 intervenciones) el 03/09/2013 14:53:11
Tu codigo funciona perfecto!! gracias!
En una ocasión vi un codigo que ponia algo asi para declarar el evento, pero no encuentro la forma correcta!

Sub sbValidaVariosTxt(xTxt As TextBox)Ctl1M.Click, Ctl1T.click, Ctl1N.click, Ctl2M.click

If xTxt.Value = 0 Then
xTxt.Value = 1
Else
If xTxt.Value = 1 Then
xTxt.Value = 2
Else
If xTxt.Value = 2 Then
xTxt.Value = 0
End If
End If
End If

End Sub

Muchas gracias de todas formas!
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