error: Expected End Sub

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DavidPT
    New Member
    • Oct 2008
    • 44

    error: Expected End Sub

    Hi,

    Im getting this error mesage, for the below code. I have tried to add END Sub at the end but still didnt work

    Any ideas?
    Code:
    Private Sub Command45_Enter()
    Function updateList()
    're-create query stuff
    Me.lstName.ControlSource = "Form_hours worked"
    Me.lstName.Requery
    End Function
    Last edited by NeoPa; Mar 5 '09, 02:33 PM. Reason: Please use the [CODE] tags provided
  • Dan2kx
    Contributor
    • Oct 2007
    • 365

    #2
    because you open with "sub"
    and end with "function"
    They should be the same, one or the other

    Comment

    • DavidPT
      New Member
      • Oct 2008
      • 44

      #3
      Yeah i tried End Sub.

      So what are you suggesting

      Comment

      • Dan2kx
        Contributor
        • Oct 2007
        • 365

        #4
        replace end function with end sub

        Comment

        • DavidPT
          New Member
          • Oct 2008
          • 44

          #5
          Originally posted by Dan2kx
          replace end function with end sub
          Just tried this still getting the same error message

          Comment

          • Dan2kx
            Contributor
            • Oct 2007
            • 365

            #6
            Code:
            Private Sub Command45_Enter()
            're-create query stuff
            Me.lstName.ControlSource = "Form_hours worked"
            Me.lstName.Requery
            End Sub
            You tried that?

            or

            Code:
            Private Sub Command45_Enter()
            call updateList()
            End Sub
            Code:
            Function updateList()
            're-create query stuff
            Me.lstName.ControlSource = "Form_hours worked"
            Me.lstName.Requery
            End Function

            Comment

            • DavidPT
              New Member
              • Oct 2008
              • 44

              #7
              Tried all of the above didnt work. If i change the code to much i think it will effect my access form.

              Comment

              • smartchap
                New Member
                • Dec 2007
                • 236

                #8
                I think you may try the following code:
                Code:
                Private Sub Command45_Enter()
                updateList()
                're-create query stuff
                Me.lstName.ControlSource = "Form_hours worked"
                Me.lstName.Requery
                End Sub
                where I assume that updateList() is a function defined by you somewhere else in the code.
                Last edited by NeoPa; Mar 5 '09, 02:32 PM. Reason: Please use the [CODE] tags provided

                Comment

                • missinglinq
                  Recognized Expert Specialist
                  • Nov 2006
                  • 3533

                  #9
                  Originally posted by DavidPT
                  Private Sub Command45_Enter ()
                  Function updateList()
                  're-create query stuff
                  Me.lstName.Cont rolSource = "Form_hours worked"
                  Me.lstName.Requ ery
                  End Function
                  We're all guessing, of course, without seeing all of the pertinent code, but you've apparently Copy and Pasted a function in the middle of a sub, which you can't do! Somewhere below the code you posted I suspect you have an End Sub, possibly with code preceding it, that should be closing Sub Command45_Enter ().

                  My advice would be to delete all the code you posted, and look for the stray, unmatched, End Sub , delete it, and start over again.

                  Linq ;0)>

                  Comment

                  • DavidPT
                    New Member
                    • Oct 2008
                    • 44

                    #10
                    Thanks for the replys this is the whole code
                    Code:
                    Private Sub Command45_Click()
                    On Error GoTo Err_Command45_Click
                    
                    
                        DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
                    
                    Exit_Command45_Click:
                        Exit Sub
                    
                    Err_Command45_Click:
                        MsgBox Err.Description
                        Resume Exit_Command45_Click
                        
                    End Sub
                    
                    Private Sub Command45_Enter()
                    Function updateList()
                    're-create query stuff
                    Me.lstName.ControlSource = "Form_hours worked"
                    Me.lstName.Requery
                    End Function
                    Last edited by NeoPa; Mar 5 '09, 02:34 PM. Reason: Please use the [CODE] tags provided

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32633

                      #11
                      As a full member now, you should know that we expect your code to be posted in [CODE] tags (See How to Ask a Question).
                      This makes it easier for our Experts to read and understand it.

                      Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

                      Please use the tags in future.

                      Administrator.

                      PS. Tags are done as matching pairs where the opening one is surrounded by [...] and the closing one by [/...]. A set of buttons is available for ease of use in the Standard Editor (Not the Basic Editor). The one for the [ CODE ] tags has a hash (#) on it. You can choose which editor to use in your profile options (Look near the bottom of the page).

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32633

                        #12
                        David, You need an End Sub line after line #16 and before trying to start a new procedure in line #17.

                        After the explanations already posted I fail to see why you should need to post this here for someone to do for you. It's fair enough if you simply can't understand what's being said, but you make no mention of that. You simply post the code for someone to tell you the precise answer. I have to say I can't see that attitude winning you many friends here.

                        Comment

                        Working...