good day ! Forum,
I am trying to append some data from an excel sheet. Following code used for same and successful. However, i need to put few condition while importing the data to the Access table. i.e;
Table : tblMain
Filed : Vessel, Voyage, contianerNo, ......, ......, .....,
while importing, need to check whrt "containerNo" which is importing already in the table under the particular voyage. If yes error msg should pop up warning that the particular container is already exists. If same container number is already exists in the same table under a different voyage, data should be imported without any error.
Kindly request a possible amendment to below code to meet above requirement.
Code
Private Sub Command0_Click()
Dim Filepath As String
Filepath = "D:\Xxxx\tbl_Impts_main.xlsx"
If FileExist(Filepath) Then
DoCmd.TransferSpreadsheet acImport, , "MainImportsfromxls", Filepath, True
If IsNull(DLookup("[ContainerNo]", "newdata")) Then
MsgBox " No neW data to add"
Else
DoCmd.OpenQuery "data_ApendtoMain", acViewNormal
MsgBox " New data Imported"
End If
Else
MsgBox "Data Source file is not available. Please check the file name or location.", vbInformation, " Data source file not available"
End If
DoCmd.DeleteObject acTable, "MainImportsfromxls"
End Sub
Code Source : https://www.youtube.com/watch?v=vQZRadmm7Ho
I am trying to append some data from an excel sheet. Following code used for same and successful. However, i need to put few condition while importing the data to the Access table. i.e;
Table : tblMain
Filed : Vessel, Voyage, contianerNo, ......, ......, .....,
while importing, need to check whrt "containerNo" which is importing already in the table under the particular voyage. If yes error msg should pop up warning that the particular container is already exists. If same container number is already exists in the same table under a different voyage, data should be imported without any error.
Kindly request a possible amendment to below code to meet above requirement.
Code
Private Sub Command0_Click()
Dim Filepath As String
Filepath = "D:\Xxxx\tbl_Impts_main.xlsx"
If FileExist(Filepath) Then
DoCmd.TransferSpreadsheet acImport, , "MainImportsfromxls", Filepath, True
If IsNull(DLookup("[ContainerNo]", "newdata")) Then
MsgBox " No neW data to add"
Else
DoCmd.OpenQuery "data_ApendtoMain", acViewNormal
MsgBox " New data Imported"
End If
Else
MsgBox "Data Source file is not available. Please check the file name or location.", vbInformation, " Data source file not available"
End If
DoCmd.DeleteObject acTable, "MainImportsfromxls"
End Sub
Code Source : https://www.youtube.com/watch?v=vQZRadmm7Ho