reference to opened form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
I have a "MAIN" form where i set filters. I choose a condition in a combo,
then press button to show results in other form.
On that other form i have a button to open report which is supposed to show
the same data filtered according to condition set on MAIN form.

But i somehow fail to address MAIN form. Instead of opening the report it
sais it cannot find field "Forms". What is wrong in my code?

If IsNull(Me!Forms!MAIN!Status1) Then
DoCmd.OpenReport stDocName, acPreview
Else
stLinkCriteria = "[PrStatus]=" & Me!Forms!MAIN!Status1.Column(1)
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
End If

Thank you.
Lana
 
if you're running the code from the MAIN form, then you don't need to
reference the Forms! collection at all, as

If IsNull(Me!Status1) Then

stLinkCriteria = "[PrStatus]=" & Me!Status1.Column(1)

the Me keyword is used to refer to the open form that the code is running
from. if you're running the code from another form, then you should not use
the Me reference, because the Status1 control is not on the form where the
code is running, as

If IsNull(Forms!MAIN!Status1) Then

stLinkCriteria = "[PrStatus]=" & Forms!MAIN!Status1.Column(1)

you use the full reference Forms!FormName! when your code is refering to
*another* open form, not the form that the code is running from.

hth
 
Thank you Tina,
I deleted "Me." and it worked fine! :)
Lana


tina said:
if you're running the code from the MAIN form, then you don't need to
reference the Forms! collection at all, as

If IsNull(Me!Status1) Then

stLinkCriteria = "[PrStatus]=" & Me!Status1.Column(1)

the Me keyword is used to refer to the open form that the code is running
from. if you're running the code from another form, then you should not use
the Me reference, because the Status1 control is not on the form where the
code is running, as

If IsNull(Forms!MAIN!Status1) Then

stLinkCriteria = "[PrStatus]=" & Forms!MAIN!Status1.Column(1)

you use the full reference Forms!FormName! when your code is refering to
*another* open form, not the form that the code is running from.

hth


Lana said:
Hi all,
I have a "MAIN" form where i set filters. I choose a condition in a combo,
then press button to show results in other form.
On that other form i have a button to open report which is supposed to show
the same data filtered according to condition set on MAIN form.

But i somehow fail to address MAIN form. Instead of opening the report it
sais it cannot find field "Forms". What is wrong in my code?

If IsNull(Me!Forms!MAIN!Status1) Then
DoCmd.OpenReport stDocName, acPreview
Else
stLinkCriteria = "[PrStatus]=" & Me!Forms!MAIN!Status1.Column(1)
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
End If

Thank you.
Lana
 
Back
Top