Validar campos de formulario para no permitir registro incompleto
Publicado por Ali (7 intervenciones) el 27/03/2017 17:46:05
Hola buen día
Me encuentro comenzando en el desarrollo de access+vb y me gustaria si me pudieran orientar en un asunto.
Verán:
Tengo un formulario con 7 campos, de los cuales soló uno se encuentra validado para que no quede vacio, su código es el siguiente:
Comprendo que debo crear métodos iguales por cada campo que quiera validar y mandarlo a llamar a la hora de hacer el registro, el problema es en el método para insertar el registro, ya que no logro que funcione, agradecería su orientación, el código es el siguiente:
Me encuentro comenzando en el desarrollo de access+vb y me gustaria si me pudieran orientar en un asunto.
Verán:
Tengo un formulario con 7 campos, de los cuales soló uno se encuentra validado para que no quede vacio, su código es el siguiente:
1
2
3
4
5
6
7
8
9
10
11
Public Sub validarDocumento() 'Validamos que el campo de "Nombre del documento" no esté vacío
txtDocumento.SetFocus
If (txtDocumento.Text = "") Then
valida = False
MsgBox "Introduce el nombre del registro", vbApplicationModal + vbCritical + vbOKOnly, "SISTEMA DE GESTION DE REGISTROS"
txtDocumento.SetFocus
Else
valida = True
guardar.SetFocus
End If
End Sub
Comprendo que debo crear métodos iguales por cada campo que quiera validar y mandarlo a llamar a la hora de hacer el registro, el problema es en el método para insertar el registro, ya que no logro que funcione, agradecería su orientación, el código es el siguiente:
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
Private Sub guardar_Click() 'Método para guardar un registro
Dim guardar
DoCmd.SetWarnings (False) 'Ocultamos los avisos de Access
Me.validarDocumento 'Se valida de que el campo documento no esté vacío
If (valida = True) Then 'Si txtDocumento contiene texto
guardar = MsgBox("¿Son Correctos los datos?", vbApplicationModal + vbExclamation + vbYesNo, "SISTEMA DE GESTION DE REGISTROS")
If (guardar = vbYes) Then
Select Case almacen 'Verificamos qué almacén se eligió
Case 1 'Almacen 1
If (nueva = True) Then 'Si elegimos un área personalizada
Me.guardarRegistroAreaPersonalizadaSQL 'Guardamos el registro
Me.actualizarAlmacen1SQL 'Actualizamos el campo "Ocupado" del almacén
labelLoc.Visible = False
txtLoc.Visible = False
listaAreas.Enabled = True
listaAreas.Visible = False
listaSubarea.Enabled = True
listaSubarea.Visible = False
opcPersonalizada.Value = ""
opcPersonalizada.Enabled = True
opcPersonalizada.Visible = False
listaAreasPersonalizadas.Value = ""
listaAreasPersonalizadas.Visible = False
agregar.Enabled = True
agregar.Visible = False
Me.borrarCampos
Me.desbloquearListas
Me.cargarListas
Variables.Posicion = txtLoc.Value
DoCmd.OpenForm "Mensaje_Nuevo", acNormal
End If
If (nueva = False) Then 'Si elegimos un área que no es personalizada
Me.guardarRegistroSQL 'Guardamos el registro
Me.actualizarAlmacen1SQL 'Acutalizamos el campo "Ocupado" del Almacen
labelLoc.Visible = False
txtLoc.Visible = False
listaAreas.Enabled = True
listaAreas.Visible = False
listaSubarea.Enabled = True
listaSubarea.Visible = False
listaAreasPersonalizadas.Value = ""
listaAreasPersonalizadas.Visible = False
opcPersonalizada.Value = ""
opcPersonalizada.Visible = False
Me.borrarCampos
Me.desbloquearListas
Me.cargarListas
Variables.Posicion = txtLoc.Value
DoCmd.OpenForm "Mensaje_Nuevo", acNormal
End If
Case 2 'Almacen 2
If (nueva = True) Then
Me.guardarRegistroAreaPersonalizadaSQL
Me.actualizarAlmacen2SQL
labelLoc.Visible = False
txtLoc.Visible = False
listaAreas.Enabled = True
listaAreas.Visible = False
listaSubarea.Enabled = True
listaSubarea.Visible = False
opcPersonalizada.Value = ""
opcPersonalizada.Enabled = True
opcPersonalizada.Visible = False
listaAreasPersonalizadas.Value = ""
listaAreasPersonalizadas.Visible = False
agregar.Enabled = True
agregar.Visible = False
txtArea.Locked = False
Me.borrarCampos
Me.desbloquearListas
Me.cargarListas
Variables.Posicion = txtLoc.Value
DoCmd.OpenForm "Mensaje_Nuevo", acNormal
End If
If (nueva = False) Then
Me.guardarRegistroSQL 'Guardamos el registro
Me.actualizarAlmacen2SQL 'Acutalizamos la tabla Almacen2
labelLoc.Visible = False
txtLoc.Visible = False
listaAreas.Enabled = True
listaAreas.Visible = False
listaSubarea.Enabled = True
listaSubarea.Visible = False
opcPersonalizada.Value = ""
opcPersonalizada.Visible = False
Me.borrarCampos
Me.desbloquearListas
Me.cargarListas
Variables.Posicion = txtLoc.Value
DoCmd.OpenForm "Mensaje_Nuevo", acNormal
End If
Case 3 'Almacen 3
If (nueva = True) Then
Me.guardarRegistroAreaPersonalizadaSQL
Me.actualizarAlmacen3SQL
labelLoc.Visible = False
txtLoc.Visible = False
listaAreas.Enabled = True
listaAreas.Visible = False
listaSubarea.Enabled = True
listaSubarea.Visible = False
opcPersonalizada.Value = ""
opcPersonalizada.Enabled = True
opcPersonalizada.Visible = False
listaAreasPersonalizadas.Value = ""
listaAreasPersonalizadas.Visible = False
agregar.Enabled = True
agregar.Visible = False
txtArea.Locked = False
Me.borrarCampos
Me.desbloquearListas
Me.cargarListas
Variables.Posicion = txtLoc.Value
DoCmd.OpenForm "Mensaje_Nuevo", acNormal
End If
If (nueva = False) Then
Me.guardarRegistroSQL 'Guardamos el registro
Me.actualizarAlmacen3SQL 'Acutalizamos la tabla Almacen3
labelLoc.Visible = False
txtLoc.Visible = False
listaAreas.Enabled = True
listaAreas.Visible = False
listaSubarea.Enabled = True
listaSubarea.Visible = False
opcPersonalizada.Value = ""
opcPersonalizada.Visible = False
Me.borrarCampos
Me.desbloquearListas
Me.cargarListas
Variables.Posicion = txtLoc.Value
DoCmd.OpenForm "Mensaje_Nuevo", acNormal
End If
Case 4 'Almacen 4
If (nueva = True) Then
Me.guardarRegistroAreaPersonalizadaSQL
Me.actualizarAlmacen4SQL
labelLoc.Visible = False
txtLoc.Visible = False
listaAreas.Enabled = True
listaAreas.Visible = False
listaSubarea.Enabled = True
listaSubarea.Visible = False
opcPersonalizada.Value = ""
opcPersonalizada.Enabled = True
opcPersonalizada.Visible = False
listaAreasPersonalizadas.Value = ""
listaAreasPersonalizadas.Visible = False
agregar.Enabled = True
agregar.Visible = False
txtArea.Locked = False
Me.borrarCampos
Me.desbloquearListas
Me.cargarListas
Variables.Posicion = txtLoc.Value
DoCmd.OpenForm "Mensaje_Nuevo", acNormal
End If
If (nueva = False) Then
Me.guardarRegistroSQL 'Guardamos el registro
Me.actualizarAlmacen4SQL 'Acutalizamos la tabla Almacen4
labelLoc.Visible = False
txtLoc.Visible = False
listaAreas.Enabled = True
listaAreas.Visible = False
listaSubarea.Enabled = True
listaSubarea.Visible = False
opcPersonalizada.Value = ""
opcPersonalizada.Visible = False
Me.borrarCampos
Me.desbloquearListas
Me.cargarListas
Variables.Posicion = txtLoc.Value
DoCmd.OpenForm "Mensaje_Nuevo", acNormal
End If
Case 5 'Almacen 5
If (nueva = True) Then
Me.guardarRegistroAreaPersonalizadaSQL
Me.actualizarAlmacen5SQL
labelLoc.Visible = False
txtLoc.Visible = False
listaAreas.Enabled = True
listaAreas.Visible = False
listaSubarea.Enabled = True
listaSubarea.Visible = False
opcPersonalizada.Value = ""
opcPersonalizada.Enabled = True
opcPersonalizada.Visible = False
listaAreasPersonalizadas.Value = ""
listaAreasPersonalizadas.Visible = False
agregar.Enabled = True
agregar.Visible = False
txtArea.Locked = False
Me.borrarCampos
Me.desbloquearListas
Me.cargarListas
Variables.Posicion = txtLoc.Value
DoCmd.OpenForm "Mensaje_Nuevo", acNormal
End If
If (nueva = False) Then
Me.guardarRegistroSQL 'Guardamos el registro
Me.actualizarAlmacen5SQL 'Acutalizamos la tabla Almacen5
labelLoc.Visible = False
txtLoc.Visible = False
listaAreas.Enabled = True
listaAreas.Visible = False
listaSubarea.Enabled = True
listaSubarea.Visible = False
opcPersonalizada.Value = ""
opcPersonalizada.Visible = False
Me.borrarCampos
Me.desbloquearListas
Me.cargarListas
Variables.Posicion = txtLoc.Value
DoCmd.OpenForm "Mensaje_Nuevo", acNormal
End If
Case break
End Select
nueva = False
End If
If (guardar = vbNo) Then 'Si elegimos la opción "NO", se cancela la operación
MsgBox "La operación ha sido cancelada", vbApplicationModal + vbExclamation + vbOKOnly, "SISTEMA DE GESTION DE REGISTROS"
End If
End If
End Sub
Valora esta pregunta
0