Share via

Compile error: Label not defined Access

Anonymous
2018-10-09T11:00:02+00:00

Hi All,

I am getting the above error message on the following code - I have highlighted the line it goes to. Can anyone advise how this is incorrect?

Private Sub New_Report_Click()

DoCmd.Close

On Error GoTo Err_CmdImportExcel_Click

DoCmd.TransferSpreadsheet transfertype:=acImport, tablename:="Report Temp", FileName:="~~FileNameRemoved~~xlsx", HasFieldNames:=True

Exit_CmdImportExcel_Click:

Exit Sub

Err_New_Report_Click:

MsgBox Err.Description

Resume Exit_New_Report_Click

DoCmd.RunMacro "Report"

DoCmd.OpenForm "Report"

Thanks in advance.

P.S. I have removed the filepath for confidentiality reasons but I have checked this and it is correct.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2018-10-15T20:14:37+00:00

Move the lines

DoCmd.RunMacro "Report"

DoCmd.OpenForm "Report"

to immediately above the line

Exit_New_Report_Click:

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2018-10-09T11:09:56+00:00

The line

On Error GoTo Err_CmdImportExcel_Click

refers to a label Err_CmdImportExcel_Click, but the label in your code is named Err_New_Report_Click. So the above line should be

On Error GoTo Err_New_Report_Click

Also, the line

Exit_CmdImportExcel_Click:

should be

Exit_New_Report_Click:

Please note that the lines

DoCmd.RunMacro "Report"

DoCmd.OpenForm "Report"

will never be executed.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2018-10-15T16:05:30+00:00

    Hi,

    Thank you for the help - This has fixed that problem. How do I need to rephrase/change this so that the last two actions are completed?

    Thanks,

    Briony

    Was this answer helpful?

    0 comments No comments
  2. ScottGem 68,830 Reputation points Volunteer Moderator
    2018-10-09T11:05:20+00:00

    No line was highlighted, but I think I see the problem. Your On Error command defines Err_CmdImportExcel_Click as the label to go to when an error occurs. However, the label in you code is Err_New_Report_Click:

    So Err_CmdImportExcel_Click is not defined anyplace.

    Was this answer helpful?

    0 comments No comments