Query for field on form

I am trying to build a query will pull up data based on the field of a form. The problem is I would like to do this without stating the exact form. We have 9 different form that are nearly identical. All the forms will have a button that will have a report based on that query.

I tried: WHERE ((([Memo List Table].MemoNumber)=[Me].[MemoNumber]));

I was hoping that would simply look for the form that the button was on. Is there away to state something like [CurrentForm].[MemoNumber]

I hope I made enough sense! Thanks for the help! Happy Friday
cansevinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeCommented:
The way I generally try to do this is to use a temporary variable, which can be referenced in a query.  I set the value in the Current event of each form, and in the AfterUpdate event of the control.

Private Sub Form_Current

    tempvars!MemoNumber = NZ(me![MemoNumber], 0)

End Sub

Private Sub txt_MemoNumber_AfterUpdate

    tempvars!MemoNumber = NZ(me.txt_MemoNumber.Value, 0)

End Sub

Open in new window

Then, in you reports query, you can use:

WHERE [MemoNumber] = [Tempvars]![MemoNumber]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cansevinAuthor Commented:
Sounds more difficult than I wanted. Can I refer to something in a label? Will it pull the value from that? If so, that would work just fine. Thanks!
0
Nick67Commented:
All the forms will have a button that will have a report based on that query.
You are opening a report.
Therefore you can pass in OpenArgs
And OpenArgs can be the value of your desired control.
DoCmd.OpenReport stDocName, acNormal, , , , Me.[memo number]
and then you build the recordsource in the Open() event of the report.
Me.RecordSource = "select someStuff from somequery where something = " & me.openargs
0
cansevinAuthor Commented:
Thanks Dale! Got it to work.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.