Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6230637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:47:04+00:00 2026-05-24T09:47:04+00:00

I have a subroutine that runs when I click a button on my form.

  • 0

I have a subroutine that runs when I click a button on my form. The problem is that no matter what happens, the error block is executed, and I can’t figure out why. I’m not very good with Access VBA, so it may be a simple error.

Here’s my sub:

Public Sub findRecord()

    Dim rs As DAO.Recordset

    Set rs = Me.[dbo_NCL_SimmonsCodes subform1].Form.Recordset

    rs.FindFirst "NCL_ItemNum=""LSIM-" & Me.Text0 & """"

    If rs.NoMatch Then

         MsgBox "No match found.  Please try again." & vbNewLine & vbNewLine & "If this is a new item, please click the Add Record button to add.", vbInformation, "No Match"

    End If

On Error GoTo description_Error

    Me.lblDescription.Caption = DLookup("Description", "dbo_AL_ItemUPCs", "ItemCode ='" & Me.Text0 & "'")

Exit_FindRecord:
    Exit Sub

description_Error:

        MsgBox "Error " & Err.Number & ": " & Err.Description & vbNewLine & vbNewLine, vbExclamation, "VBA Error " & Err.Number
        Me.lblDescription.Caption = "Error."
        Resume Exit_FindRecord

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:47:04+00:00Added an answer on May 24, 2026 at 9:47 am

    Actually looks like a logic error. If the FindFirst statement has no match, it the routine should exit there, instead of continuing. I added ‘Exit Sub’ below that messagebox, and now I’m good.

    Public Sub findRecord()
    
        Dim rs As DAO.Recordset
    
        Set rs = Me.[dbo_NCL_SimmonsCodes subform1].Form.Recordset
    
        rs.FindFirst "NCL_ItemNum=""LSIM-" & Me.Text0 & """"
    
            If rs.NoMatch Then
                    MsgBox "No match found.  Please try again." & vbNewLine & vbNewLine & "If this is a new item, please click the Add Record button to add.", vbInformation, "No Match"
                    Me.lblDescription.Caption = "Error - No match."
                    Exit Sub      
                    '^^Added^^'
            End If
    
    On Error GoTo description_Error
    
                Me.lblDescription.Caption = DLookup("Description", "dbo_AL_ItemUPCs", "ItemCode ='" & Me.Text0 & "'")
    
    Exit_FindRecord:
            Exit Sub
    
    description_Error:
            MsgBox "Error " & Err.Number & ": " & Err.Description & vbNewLine & vbNewLine, vbExclamation, "VBA Error " & Err.Number
            Me.lblDescription.Caption = "Error."
            Resume Exit_FindRecord
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a subroutine/method that a user can call to test some
I have this Perl subroutine that is causing a problem: sub new { my
I have a subroutine in VBA that is executed when we open a PowerPoint
I have a subroutine that takes a filehandle as an argument. How do I
I often have a subroutine in Perl that fills an array with some information.
I have code that calls an ENTRY in a SUBROUTINE before the SUBROUTINE .
I have a subroutine that changes its operation slightly to include either one list
Good practice dictates that subroutine arguments in Fortran should each have a specified intent
I have a subroutine that returns a reference to a hash. I want to
I have a subroutine in Perl that should be indented like this: sub GetFiles

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.