Visual Basic - Else Without If

Life is soft - evento anual de software empresarial
 
Vista:

Else Without If

Publicado por Dark Jacob 666 (19 intervenciones) el 04/04/2006 21:57:59
este es mi codigo:

Private Sub CmdGuardar_Click()
If Data1.Recordset.BOF Then GoTo Error
Error = MsgBox("El campo ID no puede quedar vacio")
Data1.Recordset.Update
Else
End If
Cmdeliminar.Enabled = True
CmdBuscar.Enabled = True
Cmdsiguiente.Enabled = True
CmdUltimo.Enabled = True
CmdInicio.Enabled = True
CmdAnterior.Enabled = True
CmdEditar.Enabled = True
Cmdexit.Enabled = True
Cmdnuevo.Enabled = True
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
Text7.Enabled = False
Text8.Enabled = False
Text9.Enabled = False
End Sub

y pues lo ke kiero hacer es ke cuando agregues uno nuevo y le das guardar sin agregar ningun dato, me mande un mensaje de error, porke el campo ID no debe kedar vacio.

pero me marca un error: "Else Without If"

saludos
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

RE:Else Without If

Publicado por SemperFiMXL (74 intervenciones) el 04/04/2006 22:42:07
Suponiendo que todo lo demas este ok, corrige tu codigo asi ..

Private Sub CmdGuardar_Click()

If Data1.Recordset.BOF Then
MsgBox "El campo ID no puede quedar vacio"
Exit Sub
EndIf

Data1.Recordset.Update

CmdBuscar.Enabled = True
Cmdsiguiente.Enabled = True
CmdUltimo.Enabled = True
CmdInicio.Enabled = True
CmdAnterior.Enabled = True
CmdEditar.Enabled = True
Cmdexit.Enabled = True
Cmdnuevo.Enabled = True
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
Text7.Enabled = False
Text8.Enabled = False
Text9.Enabled = False

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
0
Comentar

RE:Else Without If

Publicado por Dark Jacob 666 (19 intervenciones) el 04/04/2006 23:05:54
em sigue marcandome un error pero al darle DEBUG se va a la linea

Data1.Recordset.Update

en si tengo el mismo problema

gracias
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

RE:Else Without If

Publicado por pepon (89 intervenciones) el 05/04/2006 10:06:58
Inténtalo sustituyendo la condición:
If Data1.Recordset.BOF Then
por esta otra:
If IsNull(Data1.Recordset.Fields("ID")) Then
Saludos.
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

RE:Else Without If

Publicado por José Carlos (340 intervenciones) el 06/04/2006 13:12:37
el error lo tienes en que te falta un IF, pues la sentencia

IF DATA1.RECORDSET.BOF THEN GOTO ERROR
...
ELSE
...
ENDIF
El último ENDIF le falta el IF, pues la primera línea está terminada, tiene el IF y el THEN NO LE HACE FALTA PONERLE EL ENDIF, por tanto te falta un IF, prueba así

IF DATA1.RECORDSET.BOF THEN GOTO ERROR
IF OTRA CONDICIÓN THEN
...
ELSE
...
ENDIF

Saludos
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