Custom Error Msg for Import (1 Viewer)

Access_Help

Registered User.
Local time
Today, 08:31
Joined
Feb 12, 2005
Messages
136
Hi,

I am looking to make a custom messages for this code, If it imports successfully then output "Import Successful" else "Error in Source File".

New to coding, so any pre-written script to help would be appreciated.





Code:
Private Sub cmdImportExcel_Click()

'the path to the excel workbook
Dim strExcelPath As String

strExcelPath = Environ("USERPROFILE") & "\My Documents\Students.xlsx"
'import data from excel
Call DoCmd.TransferSpreadsheet(acImport, _
acSpreadsheetTypeExcel8, "Students", strExcelPath, _
True, "A1:D11")

On Erro GoTo ErrorHanMsg1
MsgBox "Import Successful", , "Ok - 1"

Exit Sub
'This comes before End Sub or End Function Statement
ErrorHanMsg1:
MsgBox Err.Number & vbCr & Err.Description
 

Attachments

  • error.JPG
    error.JPG
    51.8 KB · Views: 189

theDBguy

I’m here to help
Staff member
Local time
Today, 08:31
Joined
Oct 29, 2018
Messages
21,358
Hmm, to do that, the only thing I could think of is to import the data into a temp table and then use a recordset to loop through the records to check for valid data and compose your error message.
 

vba_php

Forum Troll
Local time
Today, 10:31
Joined
Oct 6, 2019
Messages
2,884
do u want an error message if the import completely fails or if there is just *some* data that is not imported, but the rest is? you already have an error handler in your code, so you can simply modify the conditional statement in the error handler to:
Code:
msgbox "Error in Source File", vbCritical
 

Users who are viewing this thread

Top Bottom