Connecting Tech Pros Worldwide Forums | Help | Site Map

Overwrite duplicates

kiwichico
Guest
 
Posts: n/a
#1: Nov 12 '05
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
Guest
 
Posts: n/a
#2: Nov 12 '05

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!Field1) & "") > 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.org (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.<<


kiwichico
Guest
 
Posts: n/a
#3: Nov 12 '05

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!Field1) & "") > 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]
Closed Thread