Ayuda en Validar Registros que se Repitan
Como ha para Validar que no se inserten 2 campos solo cuando estos sean iguales, tengo una tabla con el los campos Calle, Colonia, CP
Lo que quiero es que solo cuando calle y colonia sean iguales que no permita insertarlos pero mientras uno de ellos sea diferente que lo permita
Estoy utilizando ADO
De antemano Gracias
Este Codigo lo tengo pero solo es para validar un campo
Set MiConexion = New ADODB.Connection
Set MisRegistros = New ADODB.Recordset
MiConexion.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + App.Path & "PEPE.mdb" + ";Persist Security Info=False"
MiConexion.Open
MisRegistros.Open "Base_de_Datos", MiConexion, adOpenDynamic, adLockOptimistic
Set Text19.DataSource = MisRegistros
Text19.DataField = MisRegistros.Fields(1).Name
If MisRegistros.BOF <> True And MisRegistros.EOF <> True Then
MisRegistros.MoveFirst
End If
While MisRegistros.EOF = False And Trim(Text13.Text) <> Trim(Combo2.Text)
MisRegistros.MoveNext
Wend
If MisRegistros.EOF = False Then
X = MsgBox("Datos Repetidos", vbExclamation, "Advertencia")
MisRegistros.Close
Set MisRegistros = Nothing
MiConexion.Close
Set MiConexion = Nothing
Lo que quiero es que solo cuando calle y colonia sean iguales que no permita insertarlos pero mientras uno de ellos sea diferente que lo permita
Estoy utilizando ADO
De antemano Gracias
Este Codigo lo tengo pero solo es para validar un campo
Set MiConexion = New ADODB.Connection
Set MisRegistros = New ADODB.Recordset
MiConexion.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + App.Path & "PEPE.mdb" + ";Persist Security Info=False"
MiConexion.Open
MisRegistros.Open "Base_de_Datos", MiConexion, adOpenDynamic, adLockOptimistic
Set Text19.DataSource = MisRegistros
Text19.DataField = MisRegistros.Fields(1).Name
If MisRegistros.BOF <> True And MisRegistros.EOF <> True Then
MisRegistros.MoveFirst
End If
While MisRegistros.EOF = False And Trim(Text13.Text) <> Trim(Combo2.Text)
MisRegistros.MoveNext
Wend
If MisRegistros.EOF = False Then
X = MsgBox("Datos Repetidos", vbExclamation, "Advertencia")
MisRegistros.Close
Set MisRegistros = Nothing
MiConexion.Close
Set MiConexion = Nothing
pon esto en el evento keypress
tambien te pongo el codigo de la funcion busqueda
cada vez que cambies de un text al otro se ejecuta el codigo de la funcion y te valida la informacion del los text, para ve si existe en la caja de texto
Private Sub Busqueda()
Dim rst As New ADODB.Recordset
Dim SQLSecurity As String
SQLSecurity = "SELECT * FROM usuario " _
& "WHERE USUARIO = '" & UCase(Text1(1)) & "' " _
& "or CLAVE = '" & UCase(Text1(2)) & "'" _
& "or NOMBRES = '" & UCase(Text1(0)) & "';"
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open SQLSecurity, cnn, adOpenForwardOnly, adLockReadOnly
If rst.RecordCount < 1 Then
existe = False
Else
existe = True
End If
End Sub
Private Sub Text1_Validate(Index As Integer, keepfocus As Boolean)
Select Case Index
Case 0
Busqueda
If existe = True Then
MsgBox "¡¡Atención!! Ya se ha creado un usuario con este Nombre:" & Text1(0) & vbCrLf & "cambie los datos y vuelva a intentarlo", vbInformation, "Usuarios"
Text1(0).SelStart = 0
Text1(0).SelLength = Len(Text1(0))
keepfocus = True
End If
If Len(Text1(0).Text) = 0 Or Len(Text1(0).Text) < 6 Then
MsgBox "Error: No puede introducir menos de 6 caracteres", vbInformation, "Usuarios"
keepfocus = True
Text1(0).Text = ""
End If
Case 1
Busqueda
If existe = True Then
MsgBox "¡¡Atención!! Ya se ha creado un usuario con este Nombre de Usuario:" & Text1(1) & vbCrLf & "cambie los datos y vuelva a intentarlo", vbInformation, "Usuarios"
Text1(1).SelStart = 0
Text1(1).SelLength = Len(Text1(1).Text)
keepfocus = True
End If
If Len(Text1(1).Text) < 6 Then
MsgBox "Error: No puede introducir menos de 6 caracteres", vbInformation, "Usuarios"
keepfocus = True
Text1(1).Text = ""
End If
Case 2
Busqueda
If existe = True Then
MsgBox "¡¡Atención!! Ya se ha creado un usuario con esta Clave:" & Text1(2) & vbCrLf & "cambie los datos y vuelva a intentarlo", vbInformation, "Usuarios"
Text1(2).SelStart = 0
Text1(2).SelLength = Len(Text1(2).Text)
keepfocus = True
End If
If Len(Text1(2).Text) < 6 Then
MsgBox "Error: No puede introducir menos de 6 caracteres", vbInformation, "Usuarios"
keepfocus = True
Text1(2).Text = ""
End If
Case 3
If Len(Text1(3).Text) < 6 Then
MsgBox "Error: No puede introducir menos de 6 caracteres", vbInformation, "Usuarios"
keepfocus = True
Text1(3).Text = ""
End If
End Select
End Sub
tambien te pongo el codigo de la funcion busqueda
cada vez que cambies de un text al otro se ejecuta el codigo de la funcion y te valida la informacion del los text, para ve si existe en la caja de texto
Private Sub Busqueda()
Dim rst As New ADODB.Recordset
Dim SQLSecurity As String
SQLSecurity = "SELECT * FROM usuario " _
& "WHERE USUARIO = '" & UCase(Text1(1)) & "' " _
& "or CLAVE = '" & UCase(Text1(2)) & "'" _
& "or NOMBRES = '" & UCase(Text1(0)) & "';"
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open SQLSecurity, cnn, adOpenForwardOnly, adLockReadOnly
If rst.RecordCount < 1 Then
existe = False
Else
existe = True
End If
End Sub
Private Sub Text1_Validate(Index As Integer, keepfocus As Boolean)
Select Case Index
Case 0
Busqueda
If existe = True Then
MsgBox "¡¡Atención!! Ya se ha creado un usuario con este Nombre:" & Text1(0) & vbCrLf & "cambie los datos y vuelva a intentarlo", vbInformation, "Usuarios"
Text1(0).SelStart = 0
Text1(0).SelLength = Len(Text1(0))
keepfocus = True
End If
If Len(Text1(0).Text) = 0 Or Len(Text1(0).Text) < 6 Then
MsgBox "Error: No puede introducir menos de 6 caracteres", vbInformation, "Usuarios"
keepfocus = True
Text1(0).Text = ""
End If
Case 1
Busqueda
If existe = True Then
MsgBox "¡¡Atención!! Ya se ha creado un usuario con este Nombre de Usuario:" & Text1(1) & vbCrLf & "cambie los datos y vuelva a intentarlo", vbInformation, "Usuarios"
Text1(1).SelStart = 0
Text1(1).SelLength = Len(Text1(1).Text)
keepfocus = True
End If
If Len(Text1(1).Text) < 6 Then
MsgBox "Error: No puede introducir menos de 6 caracteres", vbInformation, "Usuarios"
keepfocus = True
Text1(1).Text = ""
End If
Case 2
Busqueda
If existe = True Then
MsgBox "¡¡Atención!! Ya se ha creado un usuario con esta Clave:" & Text1(2) & vbCrLf & "cambie los datos y vuelva a intentarlo", vbInformation, "Usuarios"
Text1(2).SelStart = 0
Text1(2).SelLength = Len(Text1(2).Text)
keepfocus = True
End If
If Len(Text1(2).Text) < 6 Then
MsgBox "Error: No puede introducir menos de 6 caracteres", vbInformation, "Usuarios"
keepfocus = True
Text1(2).Text = ""
End If
Case 3
If Len(Text1(3).Text) < 6 Then
MsgBox "Error: No puede introducir menos de 6 caracteres", vbInformation, "Usuarios"
keepfocus = True
Text1(3).Text = ""
End If
End Select
End Sub
