Overwrite duplicates

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kiwichico

    #1

    Overwrite duplicates

    Hi everyone,
    I am trying to write some VBA code to overwrite duplicates in an
    existing table with records that are imported. However I don't want to
    overwrite the fields in the exisiting records if the imported file
    contains blanks in its fields. Does anyone have any suggestions?
  • Bruce M. Thompson

    #2
    Re: Overwrite duplicates

    > I am trying to write some VBA code to overwrite duplicates in an[color=blue]
    > existing table with records that are imported. However I don't want to
    > overwrite the fields in the exisiting records if the imported file
    > contains blanks in its fields. Does anyone have any suggestions?[/color]

    Are you executing sql in your code or are you opening recordsets and stepping
    through the records (or using multiple recordsets and findfirst) to update the
    values? If using recordsets, I might use this approach:

    '**
    'Assuming rs2 is already in .Edit mode
    If Len(Trim(rs1!Fi eld1) & "") > 0 Then 'If not null or zero-length strings
    rs2!Field1 = rs1!Field1
    End If
    '**

    If executing sql, I don't know that an Update query can be written to do that.

    --
    Bruce M. Thompson, Microsoft Access MVP
    bthmpson@mvps.o rg (See the Access FAQ at http://www.mvps.org/access)[color=blue][color=green]
    >> NO Email Please. Keep all communications[/color][/color]
    within the newsgroups so that all might benefit.<<


    Comment

    • kiwichico

      #3
      Re: Overwrite duplicates

      Thank for your reply. I will give this a go.
      [color=blue]
      >
      > '**
      > 'Assuming rs2 is already in .Edit mode
      > If Len(Trim(rs1!Fi eld1) & "") > 0 Then 'If not null or zero-length strings
      > rs2!Field1 = rs1!Field1
      > End If
      > '**
      >
      > If executing sql, I don't know that an Update query can be written to do that.[/color]

      Comment

      Working...