Button to open form with relative information...

lacey

Registered User.
Local time
Yesterday, 17:13
Joined
Oct 28, 2009
Messages
133
Here is my DB:
View attachment 37279
What I am trying to figure out is the best way to have, when the button is pressed, class form open with ONLY classes relative to the session selected. How can I do this?
 
Last edited:
Check out the Where Condition of the OpenForm method. Your code might look something like;
Code:
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "YourFormNameToOpen"
    
    stLinkCriteria = "[SessionID]=" & Me![ControlOnCurentFormThatHoldsSessionID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
 
Okay, I've entered some VBA coding from this website and believe I have it working right now.
Now here's my problem. I have the button set to open the Classes form. But it's opening the form with ALL classes, even though I enter the parameter value for Session 1 when it opens. I only want it to make available classes that are in the desired session. Any ideas?

Here is my DB: View attachment 37293
 
Last edited:
The problem is arising because the Where condition in your OpenForm command contains a field, Session, which does not form part of the Record Source of your form Classes.

Also consider implementing a naming protocol for your DB objects along the lines of FRM_FormName, TBL_TableName, QRY_QueryName etc. Avoid spaces and other special charters and limit yourself to alpha and numeric characters and the underscore. This will make thing clearer in your code as to the nature of the object that code is referring to. This is particularly pertinent in the case of you DB as you have both a Table and a Form called Classes :confused:
 

Users who are viewing this thread

Back
Top Bottom