Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 3022 - How to Handle 2

Status
Not open for further replies.

SummaEng

Technical User
May 28, 2011
1
CA
Hi,

I am trying to append a record from, say table1 to a another table, say table2. I am getting an error 3022 if the same record already exist in table2. What is the best way to do so that if the record already exist in table2 the error will not appear and instead a message will pop up stating that the record already exist in table2. Sample code will help. Thanks in advance.

SummaEng
 
How are ya PostSummaEng . . .

Error 3022 speaks of [blue]duplicate primarykeys[/blue]. Possible code you can use:
Code:
[blue]   Dim Cri As String
   
   [green]'Use if primarykey is numeric[/green]
   Cri = "[PrimaryKeyNameTable1]=" & InputValueTable2
   [green]'Use if primarykey is string[/green]
   Cri = "[PrimaryKeyNameTable1]='" & InputValueTable2 & "'"
   
   If IsNull(DLookup("[PrimaryKeyNameTable1]", Table1Name, Cri)) Then
      [green]'Append SQL Here[/green]
   Else
      [green]'Duplicate error message here[/green]
   End If[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
am trying to append a record
How ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top