PDA

View Full Version : Evoid Registering with duplications



marreco
04-06-2013, 04:06 AM
Hi.
Can someone help me find out, because they save the data, data duplication is registering?

Thanks

mdmackillop
04-06-2013, 04:48 AM
Can you be more specific?

marreco
04-06-2013, 04:53 AM
Hi.
when I click the save button "cmdSalvar_Click()", generates a repeated information in my database
Cod Nome endereço cidade estado
45 Name45 Stree X Texas US
45 Name45 Stree X Texas US

SamT
04-06-2013, 05:51 AM
Bad Practice:
If Not IsNumeric(lblCod.Caption) = True
.
.
.
Range("A2").Select

'Procurar a primeira célula vazia

Do
If Not (IsEmpty(ActiveCell)) Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
Better Practice
If Not IsNumeric(lblCod.Caption)
'OR
If (IsNumeric(lblCod.Caption) = False)
.
.
.
Dim URng As Range
Set URng = Range("A2")

'Procurar a primeira célula vazia

Do
If Not (IsEmpty(URng)) Then
Set URng = URng.Offset(1, 0)
End If
Loop Until IsEmpty(URng) = True

Paul_Hossler
04-06-2013, 05:58 AM
Using F8 to step through your macros, I noticed that when I saved data, both the marked lines were executed. That could be how the duplicate data is being stored



Private Sub cmdSalvar_Click()
If txtEmpresa.Enabled = True Then
If Not IsNumeric(lblCod.Caption) = True Then
lsInserir '------------------------------------------
Sheets("Menu").Activate
Else
lsAlterarStudent
Sheets("Menu").Activate
End If

lsDesabilitar
MsgBox "Registro Salvo!"
End If
'Ativar a primeira planilha
ThisWorkbook.Worksheets("BD_Empresa").Activate
'Selecionar a célula A2
Range("A2").Select
'Procurar a primeira célula vazia
Do
If Not (IsEmpty(ActiveCell)) Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
'Carregar os dados digitados nas caixas de texto para a planilha
ActiveCell.Value = lblCod_Value '----------------------------------------------
ActiveCell.Offset(0, 1).Value = txtEmpresa.Value
ActiveCell.Offset(0, 2).Value = txtEndereço.Value
ActiveCell.Offset(0, 3).Value = txtNumero.Value
ActiveCell.Offset(0, 4).Value = txtCompl.Value



Paul

marreco
04-07-2013, 09:58 AM
SAMT ol, did not work when I try to change the data with the "Change" button data is duplicated.


Paul_Hossler, I could not understand where is the error in my code.