troubleshooting Question

Doubt in SQL, need a help here

Avatar of Armando Vilela Baiões
Armando Vilela BaiõesFlag for Portugal asked on
SQLMicrosoft AccessVBA
24 Comments2 Solutions68 ViewsLast Modified:
Hello Fellows

I have this SQL, which is fetching already inserted values ​​at an old date, for records with a new date. SQl is working fine, but I have some difficulty doing the following:
If I mistakenly re-run the query, the records become duplicates, I want to avoid this with something like "WHERE NOT EXISTS", but I'm not sure how to do that part. Can you give me a hand?

Greetings to all.

SQL:
Private Sub Command39_Click()

' remind that [DATA] must be like this -> #" & Format(DataFormatada, "mm/dd/yyyy") & "#
Dim DataFormatadaOld As Date
Dim DataFormatadaNew As Date
DataFormatadaOld = Format(Forms!frmFScomposicao!ComboFSDATA, "short date")
DataFormatadaNew = Format(Forms!frmFScomposicao!TransferData, "short date")

Dim db As Database
Dim strSQL As String
Set db = CurrentDb()

strSQL = "INSERT INTO tblFSListaTecnicos (AtribDataTecnico, AtribEquipaTecnico, TecnicoLista, FuncaoTecnicoLista) " _
& "SELECT #" & Format(DataFormatadaOld, "mm/dd/yyyy") & "#, '" & Forms!frmFScomposicao!ComboFSEQUIPA & "', " _
& "TecnicoLista, FuncaoTecnicoLista " _
& "FROM tblFSListaTecnicos " _
& "WHERE ((tblFSListaTecnicos.AtribDataTecnico = #" & Format(DataFormatadaNew, "mm/dd/yyyy") & "#) And (tblFSListaTecnicos.AtribEquipaTecnico = '" & Forms!frmFScomposicao!TransferEquipa & "'))"
db.Execute strSQL, dbFailOnError
Me.Refresh
MsgBox db.RecordsAffected & " Tecnicos Adicionados"





End Sub

Thanks in advanced
ASKER CERTIFIED SOLUTION
Armando Vilela Baiões
Self-taught

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 24 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 24 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros