Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253

    Invalid outside procedure on Subform

    I am trying to write code to be able to navigate records. The buttons are on a subform and i want to move records on the main form. The following code is what i have for the previous record button. I keep getting an error saying "Invalid outside procedure". Could someone help me with my coding error? Thank you. --Walker



    Code:
    Public Sub btnPrevRec_Click()
         Dim rsC As Recordset
         Set rsC = Me.Recordset.Clone
         
         If Not rs.BOF Then
            DoCmd.GoToRecord acDataForm, Forms.frm_parts, acPrevious
            DoCmd.GoToRecord acDataForm, Me.frm_parts, acPrevious                     'Tried All the Red text versions but get the same error. 
            DoCmd.GoToRecord acDataForm, Forms.frm_parts.name, acPrevious              'I even commented out everything in the sub but each one of these lines individually. 
            DoCmd.GoToRecord acDataForm, me.frm_parts.name, acPrevious
         Else
            MsgBox "There are no previous records.", vbOKOnly + vbInformation, "NO PREVIOUS RECORDS"
         Exit Sub
        
         Set rsC = Nothing
    End Sub

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    What happens if you try this:
    Code:
    Public Sub btnPrevRec_Click()
     On Error GoTo err_previous
     DoCmd.GoToRecord acDataForm, Me.Parent.Name, acPrevious
    
    Exit sub
    err_previous:
    MsgBox "There are no previous records.", vbOKOnly + vbInformation, "NO PREVIOUS RECORDS"
    
    
         'Dim rsC As Recordset
         'Set rsC = Me.Recordset.Clone
         
         'If Not rs.BOF Then
            'DoCmd.GoToRecord acDataForm, Forms.frm_parts, acPrevious
          '  DoCmd.GoToRecord acDataForm, Me.frm_parts, acPrevious                     'Tried All the Red text versions but get the same error. 
            'DoCmd.GoToRecord acDataForm, Forms.frm_parts.name, acPrevious              'I even commented out everything in the sub but each one of these lines individually. 
            'DoCmd.GoToRecord acDataForm, me.frm_parts.name, acPrevious
         'Else
            'MsgBox "There are no previous records.", vbOKOnly + vbInformation, "NO PREVIOUS RECORDS"
         'Exit Sub
        
         'Set rsC = Nothing
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    DoCmd.GoToRecord acDataForm, Me.Parent.Name, acPrevious
    do i need to change parent or name in the code you sent? If so what are they supposed to be? My main form is frm_parts and the subform is sfrmNavBtn.

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    No, leave it as is, Me.Parent.Name will return the name of the parent form (when called from the subform).
    https://docs.microsoft.com/en-us/off...subform.parent
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    I am getting the same error. Is there anything in the properties of the parent form or subform that i need to check for?

    edit:
    I just checked another button with the following code and i get the same invalid outside procedure error.

    Code:
    Private Sub btnSearchRec_Click()
        MsgBox "Im Here"
    End Sub
    here is the exact error message
    Click image for larger version. 

Name:	iop.JPG 
Views:	12 
Size:	28.3 KB 
ID:	41600

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Can you try to set the focus on the main form before running the gotorecord:
    Me.Parent.Form.SetFocus
    Docmd.GoTORecord.....

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    My code should be in the subform, correct?

  8. #8
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    getting same error with trying to set focus.

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    sfrmNavBtn
    Does that mean a navigation form is involved here?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    Micron, No I started with a blank form in form design and just added 7 buttons. Here is the subform.

    Click image for larger version. 

Name:	navbtns2.JPG 
Views:	8 
Size:	43.2 KB 
ID:	41623

  11. #11
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Just to be clear, you are saying that when you clicked the button that was used to run the code you show in post 5, you get the error message shown in that post? If so, then how do you create your procedures, from the drop downs in the vb editor or from the form property sheet? I'd go to the property sheet line for your event(s) and click on the ellipses (...) to ensure that the procedure is 'connected' to the button(s). If that isn't a cure, I have to think that the form is corrupted. That or there is something you haven't show because AFAIK, the error implies that a command line lies outside of the procedure beginning and ending statements. In the message box code you show, it clearly isn't.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    Micron,

    You are the master. I made a new form and made the event(s) using the (...) like i usually do and it it gave me an error i was expecting about not being able to go to a previous record because i was at the BOF. I just copied the code within the the old form subroutine. On the old form I removed the events one at a time and tried to put them back but kept getting the same error. Now with new form it works. Thank you. Do you know why that happens? Thanks again --Walker

  13. #13
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Not absolutely sure I understand the question. I'm thinking the "why that happens" is why trying to rebuild the old form didn't help but creating a new one did. Forms and other db objects can get corrupted. You might fix the problem with a decompile operation; sometimes it requires a new object. This is why it's wise to create dated backup files so you can fall back to a prior version, or retrieve a copy of something that is now broken.

    EDIT - might be a good time to mention that sometimes the code you see is not the code that has been compiled. When the versions are out of sync the only remedy is to decompile the db. This forces a complete compile of the project and will often fix such issues. A decompile can also trash a db, so use it only when necessary and it's good insurance to back up the db first.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    Sorry, What causes a new form to be corrupted like that?

  15. #15
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Just about anything I guess. Dropped packets over a network; using a db over wifi; maybe a disk write error. Some think that a save or compile while stepping through code. I think it's Gremlins.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Invalid procedure call
    By cebrower in forum Queries
    Replies: 7
    Last Post: 09-26-2018, 06:07 AM
  2. Invalid procedure call
    By RonL in forum Queries
    Replies: 0
    Last Post: 05-16-2016, 02:19 PM
  3. Invalid Procedure Call or Argument
    By Trojnfn in forum Access
    Replies: 2
    Last Post: 10-29-2012, 01:44 PM
  4. Invalid Procedure Call
    By neo651 in forum Queries
    Replies: 21
    Last Post: 09-11-2011, 12:58 PM
  5. invalid procedure call
    By johnmerlino in forum Access
    Replies: 5
    Last Post: 12-13-2010, 10:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums