Results 1 to 5 of 5
  1. #1
    mcomp72 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    92

    VBA code no longer works for a form once using Navigation Form

    Hi everyone. I have a form (called Jobs) that has a button on it. When the user clicks the button, a new form (called PrintPDF_EntireJob) opens in a new window. A have a filter on that form, and the filter is based on a piece of info from the current record showing on the 'Jobs' form. The filter is applied when 'PrintPDF_EntireJob' loads.

    I wrote code to do the filtering, and it works perfectly. Here it is:

    Code:
    Private Sub Form_Load()
    
    Dim CurrentJobID As Integer
    
    CurrentJobID = Forms![Jobs]![JobID]
    
    With Forms![PrintPDF_EntireJob]
    
        .Filter = "JobID = " & CurrentJobID
        .FilterOn = True
    
    End With
    
    End Sub
    The problem comes in when I try to use the 'Jobs' form from within a Navigation Form. I get an error on this line of code:



    Code:
    CurrentJobID = Forms![Jobs]![JobID]
    Run-time error '2450':
    Microsoft Access cannot find the referenced form 'Jobs'.

    I tried removing the word "Private" from the first line of the code, but that didn't solve it.

    I searched for a solution on the web, and I did find a post on another site that seemed to discuss the exact problem. However, I could not understand it. I think I may have hit my limit on my understanding of VBA coding. Here it is, if you're curious:
    https://bytes.com/topic/access/answe...ntrol-subforms

    Anyone know how I could change the line so it will work from within the Navigation Form?

  2. #2
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    The problem comes in when I try to use the 'Jobs' form from within a Navigation Form
    By "use" I'm going to presume you mean reference it from another form, all while navigating about from within your nav form.
    A navigation form can only load one form at a time. When you open another form from within it, the first is closed. My suggestion is to forego the nav form and use a switchboard form instead. The link you provided states that to continue on your path, you will have to write code to grab the values you want, store them (some would use TempVars), open your second form and reference the stored values via coding. Depending on your design, you might then have to destroy the temp values lest they persist to another iteration (subsequent reloading) of the second form.

    Or you can pass a value to a second opening form via the OpenArgs parameter of DoCmd.OpenForm method. Methinks it's difficult to pass more than one value this way.
    You could also use the .Filter property of the opening form. The thing is, I've never used a nav form and probably never will. So I can't tell you how to interact with the action of switching from one form to another within a nav form. That is, I don't know if there's an event that occurs when doing so, that you can write code for.

    The form open event is by nature, Private. Not declaring it as private won't make its code accessible to any other process.
    Last edited by Micron; 10-04-2017 at 07:17 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    mcomp72 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    92
    Hey Micron. Thanks very much for the detailed answer. It sounds rather complicated, so I think I will forgo the Navigation Form. I can just use the regular forms I have made. Thanks again!

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    You're welcome.
    Do you not think that a switchboard form would be a viable replacement for your nav form? If you thought you needed/wanted a nav form, why not a switchboard?
    Maybe they're out of style and I"m showing my age?

  5. #5
    mcomp72 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    92
    To be completely honest, I am so new to Access, I had not heard of a switchboard before. But I'll read up on what it is and may go that route. But since I'm probably the only one that will ever use this database, it's probably just as easy for me to use the forms themselves via the Shutter Bar.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 09-04-2015, 01:47 PM
  2. Replies: 7
    Last Post: 08-16-2015, 10:10 PM
  3. Data entry form no longer works
    By Jamesiv1 in forum Access
    Replies: 1
    Last Post: 05-13-2014, 09:18 PM
  4. Replies: 11
    Last Post: 12-11-2013, 10:35 AM
  5. Replies: 6
    Last Post: 09-02-2012, 04:30 PM

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