Como validad un dato en blanco
Hola, alguien me puede ayudar, este es una parte de mi código, gracias...
Private Sub cmdgrabar_Click()
Dim insertar As Boolean
Dim op As String
If Trim(txtnombre) <> "" Then
If abrirbd Then
SQL = ""
SQL = " select * from cliente where nombre = '" & txtnombre & "'"
Set rs = bd.OpenRecordset(SQL)
If rs.EOF Then
insertar = True
Else
insertar = False
End If
If insertar Then
SQL = ""
SQL = " insert into "
SQL = SQL + " cliente "
SQL = SQL + "( nombre, direccion, cod_ciudad, cod_gerente, contacto_1, cargo_1, contacto_2, cargo_2, contacto_3, cargo_3 )"
SQL = SQL + " values ( '" & txtnombre.Text & "'"
SQL = SQL + ", '" & txtdir.Text & "'"
SQL = SQL + ", " & Val(cmbcodciudad.Text) & ""
SQL = SQL + ", " & Val(cmbcodgerente.Text) & ""
SQL = SQL + ", '" & txtnom1.Text & "'"
SQL = SQL + ", '" & txtcargo1.Text & "'"
SQL = SQL + ", '" & txtnom2.Text & "'"
SQL = SQL + ", '" & txtcargo2.Text & "'"
SQL = SQL + ", '" & txtnom3.Text & "'"
SQL = SQL + ", '" & txtcargo3.Text & "')"
bd.Execute (SQL)
MsgBox ("La información ha sido grabada...")
op = MsgBox("Desea ingresar otro", vbYesNo, "Ingreso")
If op = vbNo Then Exit Sub
limpiar
Private Sub cmdgrabar_Click()
Dim insertar As Boolean
Dim op As String
If Trim(txtnombre) <> "" Then
If abrirbd Then
SQL = ""
SQL = " select * from cliente where nombre = '" & txtnombre & "'"
Set rs = bd.OpenRecordset(SQL)
If rs.EOF Then
insertar = True
Else
insertar = False
End If
If insertar Then
SQL = ""
SQL = " insert into "
SQL = SQL + " cliente "
SQL = SQL + "( nombre, direccion, cod_ciudad, cod_gerente, contacto_1, cargo_1, contacto_2, cargo_2, contacto_3, cargo_3 )"
SQL = SQL + " values ( '" & txtnombre.Text & "'"
SQL = SQL + ", '" & txtdir.Text & "'"
SQL = SQL + ", " & Val(cmbcodciudad.Text) & ""
SQL = SQL + ", " & Val(cmbcodgerente.Text) & ""
SQL = SQL + ", '" & txtnom1.Text & "'"
SQL = SQL + ", '" & txtcargo1.Text & "'"
SQL = SQL + ", '" & txtnom2.Text & "'"
SQL = SQL + ", '" & txtcargo2.Text & "'"
SQL = SQL + ", '" & txtnom3.Text & "'"
SQL = SQL + ", '" & txtcargo3.Text & "')"
bd.Execute (SQL)
MsgBox ("La información ha sido grabada...")
op = MsgBox("Desea ingresar otro", vbYesNo, "Ingreso")
If op = vbNo Then Exit Sub
limpiar
HOLA, SI NO ESPECIFICAS CUAL ES TU ERROR SERA DIFICIL QUE ALGUIEN TE AYUDE
Si te refieres a como insertar en la base de datos un campo de texto en blanco, puedes utilizar las siguientes funciones, cuando vas a guardar el campo:
'FUNCION PARA EVITAR EL ERROR AL GUARDAR CAMPOS DE TEXTO EN BLANCO
Public Function COMPROBAR_TEXTO(TXT As Control) As Variant
If TXT.Text = "" Or IsNull(TXT.Text) Or Len(TXT) <= 0 Then
COMPROBAR_VALOR = "null"
Else
COMPROBAR_VALOR = "'" & TXT.Text & "'"
End If
End Function
'FUNCION PARA EVITAR EL ERROR AL GUARDAR CAMPOS NUMERICOS EN BLANCO
Public Function COMPROBAR_NUM(TXT As Control) As Variant
If TXT.Text = "" Or IsNull(TXT.Text) Or Len(TXT) <= 0 Then
COMPROBAR_NUM = "null"
Else
COMPROBAR_NUM = TXT.Text
End If
End Function
las declaras como publicas y puedes llamarlas desde cualquier formulario.Por ejemplo:
SQL=SQL & COMPROBAR_VALOR(NOMBRE_CAMPO)
Espero que te sirva de ayuda.
Por cierto, por casualidad no sabras como hacer para que al darle al intro en un campo de texto te salte de linea. Es que me estoy volviendo loco y no se como hacerlo. Un saludo.
'FUNCION PARA EVITAR EL ERROR AL GUARDAR CAMPOS DE TEXTO EN BLANCO
Public Function COMPROBAR_TEXTO(TXT As Control) As Variant
If TXT.Text = "" Or IsNull(TXT.Text) Or Len(TXT) <= 0 Then
COMPROBAR_VALOR = "null"
Else
COMPROBAR_VALOR = "'" & TXT.Text & "'"
End If
End Function
'FUNCION PARA EVITAR EL ERROR AL GUARDAR CAMPOS NUMERICOS EN BLANCO
Public Function COMPROBAR_NUM(TXT As Control) As Variant
If TXT.Text = "" Or IsNull(TXT.Text) Or Len(TXT) <= 0 Then
COMPROBAR_NUM = "null"
Else
COMPROBAR_NUM = TXT.Text
End If
End Function
las declaras como publicas y puedes llamarlas desde cualquier formulario.Por ejemplo:
SQL=SQL & COMPROBAR_VALOR(NOMBRE_CAMPO)
Espero que te sirva de ayuda.
Por cierto, por casualidad no sabras como hacer para que al darle al intro en un campo de texto te salte de linea. Es que me estoy volviendo loco y no se como hacerlo. Un saludo.