Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Artist,

    You should have no trouble with the link properties. Here is an example that I have just constructed (click on it to enlarge). Make sure there is an entry for Source Object.

    Click image for larger version. 

Name:	1.jpg 
Views:	11 
Size:	44.8 KB 
ID:	8960



    What does not work is the Access wizard; don't try to click on the elipsis as Access bitches and then clears the name of the link field. It's the wizard that is at fault, not the underlying subform mechanism.

  2. #17
    Artist.Anon is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    22
    Hi Rod,

    Yes I was using the '...' wizard, and can enter the data directly.

    I am not worried at all about the 3 views of the subforms, whether they are visible etc. I will make three separate subforms and put each one into a separate tab.

    All I want to be able to do is to apply a filter to these subforms with criteria from the form level.

    Regards,

  3. #18
    Artist.Anon is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    22
    Also a quick question, I have defined a public variable in a module called 'CurrentUser'. I would like to use it in a form's properties sheet / data / filter.

    Something like:
    Filter: Archived = False AND DestinationUserid = CurrentUser

    Where 'Archived' and 'DestinationUserid' are fields within the table. The first part works fine, but not the 'CurrentUser' part, so it is not recognizing that it is a public variable. What formatting should I be using?

    Cheers

  4. #19
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    I am not worried at all about the 3 views of the subforms, whether they are visible etc.
    They are only blank in the Form Design window; in Form View they all display data.

    I will make three separate subforms and put each one into a separate tab.
    Up to you of course but you triple the maintenance overhead.

    All I want to be able to do is to apply a filter to these subforms with criteria from the form level.
    We're coming to that; let's get the subforms installed and linked correctly. Give me the names of the three subform controls (not the form name) and I'll give you some sample code.

    I have defined a public variable in a module called 'CurrentUser'
    Confusion here: Is 'CurrentUser' a standard module name or a variable name?

    Filter: Archived = False AND DestinationUserid = CurrentUser
    If 'CurrentUser is a module name then it definitely won't work. You need to write DestinationUserid = CurrentUser.<myvariablename> where the last term is the name of your global variable. Global variables are declared in the declaration section of standard modules using the 'Public' keyword. Do not use form, report or class modules for global variable definition.

  5. #20
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Re Post15 - That's it! Need declaration in module header.

    I just noticed your example code shows setting Filter of mfrm1 twice. I followed that in my code and it still works to open two instances with the different filter criteria. It also works when I change the second Filter code to mfrm3. Can that be explained?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #21
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Can that be explained?
    Gremlins?

    No it had me going for a minute or two but Access is doing exactly what I told it. The second reference to mfrm1 is a mistake; it should be mfrm3. Well spotted. The delights of cut and paste!

    Access opens the first form, mfrm1 and filters it by "j*". It then opens the second form, mfrm3, and somehow the filter is carried forward to the new form. The code then resets the filter on the first form to "r*". I wondered when I tested it why the form I expected on top was underneath.

    Can't explain why the filter propagated to the second form. I have checked the property sheet and it's not to do with that. Anyway you say you get the same effect. Perhaps FilterOn sets the filter in a working copy which Access is using instaed of a file copy.

  7. #22
    Artist.Anon is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    22
    Hi

    'CurrentUser' is the variable in my module called 'Globals'

    So I have tried DestinationUserid = CurrentUser
    and DestinationUserid = Globals.CurrentUser

    and neither works. When opening the form I get prompted for CurrentUser (or Globals.CurrentUser) to enter a value.

    How do I reference a public declared variable that is set in the login page. If I msgbox (CurrentUser) on form load, it does display the value, so it is there and public.

    Confused.

  8. #23
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Here is a trivial db showing the use of a global variable in a standard module. See what's different from yours.

    MSAFUSeOfGlobal.accdb

    Open Form1 first.

  9. #24
    Artist.Anon is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    22
    Hi Rod,

    Use of a global variable in forms or vba is not where I am having the problem. Its when I try and use it on the form's property sheet under the Filter setting. Open a form in design view, click on property sheet, go down to filter, and try and filter the form where userid=global.currentuser (where userid is a field in the table belonging to the form in question) and currentuser is a public variable declared in global module.

    Once more thanks for your input,

  10. #25
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Hi Artist,

    Yes I get the same symptom when using the Property Sheet - seems to be a bug. It works however in the form's Load event.

    Code:
    Me.Filter = "DestinationUserid = " & CurrentUser
    Me.FilterOn = True
    Yet the same syntax fails in the Property Sheet - weird.

  11. #26
    Artist.Anon is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2012
    Posts
    22
    That's the piece of code I needed, I can apply that to the Enter event on the tab control.
    Thanks for all the help!

  12. #27
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    It's my experience that Access (as in queries and boxes) cannot 'see' VBA declared variables and custom constants and Sub procedures. But VBA custom Function procedure can be called by Access queries and controls, at least can in ControlSource - don't know about other properties. So a UDF could reference the global variable or constant and return the value.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 3
    Last Post: 04-17-2012, 10:28 AM
  2. Replies: 3
    Last Post: 03-29-2012, 12:40 PM
  3. Subform control via main form (or better option)
    By dwnocturnal in forum Forms
    Replies: 14
    Last Post: 11-05-2011, 11:24 AM
  4. Subform in a Tab Control on a Main form
    By jpkeller55 in forum Access
    Replies: 4
    Last Post: 01-08-2011, 12:31 PM
  5. Linking Subform Control to Main form
    By KWarzala in forum Forms
    Replies: 1
    Last Post: 03-13-2010, 08:32 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