Consulting

Results 1 to 6 of 6

Thread: Evoid Registering with duplications

  1. #1
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location

    Evoid Registering with duplications

    Hi.
    Can someone help me find out, because they save the data, data duplication is registering?

    Thanks
    Attached Files Attached Files

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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'

  3. #3
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    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

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    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

  6. #6
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •