Hi.
Can someone help me find out, because they save the data, data duplication is registering?
Thanks
Hi.
Can someone help me find out, because they save the data, data duplication is registering?
Thanks
Can you be more specific?
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
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
Bad Practice:
[vba]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[/vba]
Better Practice
[vba]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[/vba]
I expect the student to do their homework and find all the errrors I leeve in.
Please take the time to read the Forum FAQ
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
[VBA]
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
[/VBA]
Paul
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.