Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WhereCondition from one form to the next 1

Status
Not open for further replies.

Jean9

Programmer
Dec 6, 2004
128
US
Is there a way to access the value in the WhereCondition from the form that is opened? From one form another form is opened with a WhereCondition, however, because the form's recordsource is not set until its FormLoad, the WhereCondition is ignored. I'd like to access the value of it and set the filter programatically.
Thanks in advance,
J9
 
Do you mean the FILTER? If so, you can use the Filter property in the OpenForm statement: Me.filter

If you mean the WHERE condition, there must be a way you can build it, i.e. the current form shows one BuildingID, so when you click a button to see the second form, you can just put

"BuildingID = " & Me.BuildingID

in the WHERE portion of the OpenForm statement.

If none of this helps you, please tell us more, like what exactly is your "where condition" and what the purpose and recordsources of each form is.

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
It's the Where Condition. It's already being built on the calling form and I'd like to be able to reference (via code) the value in the where condition from the called form so that I can use it for the filter of the called form. Since the original purpose of the Where Condition is pretty much nullified by the form's recordsource being set on FormLoad. And actually, I get an error when I open the called form and set the recordsource. I guess the order of operations is the Where Condition before the recordsource. Soooo....
 
So does this mean that none of what I wrote helps you? If so can you please answer my original questions? We're trying to help and I've done all I can with the info you supplied, which is pretty much none at this point.

There is no stored "where condition" in the form you are sitting on. Therefore you need to build the where condition to open the second form.

What have you tried so far? HOW do you want the 2nd for opened? Where X = Y, what is X and Y? And can't you get Y from the 1st form?

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Oh. Ok.
On the calling form, a string is populated with the values that are used in the WhereCondition of the OpenForm code.

Code:
    Select Case OPT_CAL
        Case 1                  ' WASHER
            If Not Nz(Me.CbxNM, "") = "" Then sFILTER = "[APPL_APPT].[ID]=" & Me.CbxNM
            If Not Nz(Me.CbxADDRESS, "") = "" Then sFILTER = "[APPL_APPT].[ID]=" & Me.CbxADDRESS
        Case 2                  ' TOILET
            If Not Nz(Me.CbxNM, "") = "" Then sFILTER = "[APPL_APPT_T].[ID]=" & Me.CbxNM
            If Not Nz(Me.CbxADDRESS, "") = "" Then sFILTER = "[APPL_APPT_T].[ID]=" & Me.CbxADDRESS
    End Select
    
    If Not Nz(sFILTER, "") = "" Then sLINKCRIT = sFILTER

Then the form is called with
DoCmd.OpenForm sDOCNM, , , sLINKCRIT, , , sOPENARGS
where the SOPENARGS contains the value of the recordsource of the called form.

The called form contains the following code on the FormLoad event
Code:
If Not Nz(Me.OpenArgs, "") = "" Then Me.RecordSource = Me.OpenArgs

The error comes in that the WhereCondition seems to kick off first before the recordsource is set so that it cannot find the [APPL_APPT_T].[ID].

Thanks
 
Not sure if this helps by I have an application where I sort and filter a recordsource in one form and then pass this around to different forms and reports. I use a global variable for the filter and the recordset. In the called form and reports I do.

Code:
Private Sub Form_Open(Cancel As Integer)
  On Error GoTo errLbl
  Me.RecordSource = glblRsSearch.Name
  Me.filter = glblFltrSearch
  Me.FilterOn = True
  Exit Sub
errLbl:
  MsgBox Err.Number & "  " & Err.Description
  Exit Sub
End Sub
Me.RecordSource = glblRsSearch.Name
this is an A2K work around because you can not actually set the recordsource with a recordset until A2003. But you can supply the name which is a string.

In many of the calling forms I do something like.

Code:
  Set glblRsSearch = Me.RecordsetClone
  If Me.FilterOn = True Then
    glblFltrSearch = Me.filter
  Else
    glblFltrSearch = ""
  End If

 
You could either put the WHERE portion into the recordsource string, or if it's always the same form you are opening, set the filter after opening (in the code on the "calling" form):

Forms!FormNameHere.form.filter = sFilter
Forms!FormNameHere.form.filteron = True



Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top