'MS access insert query not working with WHERE clause
I Have the below code as part of Excel upload functionality. The insert query that i have used doesn't work because of the WHERE clause. Can someone please help me with suggestions.
Private Sub lblupload_Click()
Dim FSO As New FileSystemObject
Dim strsql As String
Dim strsql1 As String
Dim rs As DAO.Recordset
Dim rs1 As DAO.Recordset
If FSO.FileExists(Me.txtFileName) Then
Excelimport.importexcel Me.txtFileName, "tblimportdatatmp"
strsql = "Select distinct[Trans Day] from tblimportdatatmp;"
Set rs = CurrentDb.OpenRecordset(strsql)
If rs.RecordCount > 0 Then
rs.MoveFirst
While Not rs.EOF
strsql1 = "Select * from tblimportdata where [Trans Day] IN (select [Trans Day] from tblimportdatatmp);"
Set rs1 = CurrentDb.OpenRecordset(strsql1)
If rs1.RecordCount = 0 Then
CurrentDb.Execute "INSERT INTO tblimportdata SELECT * from tblimportdatatmp where [Trans Day] = " & rs.Fields("[Trans Day]") & " ;"
Else
MsgBox " records already exists! "
End If
rs.MoveNext
Wend
End If
Else
MsgBox "File not found !"
End If
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
