Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How open form using query rather than table

Posted on 2014-01-21
8
337 Views
Last Modified: 2014-01-22
I have a form which has it's record source as a table.

But I want to be able to open the form using a query sometimes instead.  Can this be done?

I'm trying to do it with:

DoCmd.OpenForm stDocName, acNormal, , , acFormEdit, acWindowNormal

But don't know how to make it use the query.

Or do I need to use open arguments?  There is two criteria:

ID = [Forms]![frmSelectNameAndDate]![cboName]
and
DateWorked = [Forms]![frmSelectNameAndDate]![txtDate]

--Steve
0
Comment
Question by:SteveL13
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39797906
set the recordsource to the query instead of the table. add params to the query if necessary
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39797913
Assuming that the query has the same fields as the table, you can use the Open event to change the forms RecordSource property:

me.RecordSource = "qryYourQueryName"
0
 

Author Comment

by:SteveL13
ID: 39797922
But sometimes I want the record source to be the table and other times the query.
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39797966
populate a global variable and set the form recordsource on load event.
e.g.
on load
 if var then me.recordsource = query else me.recordsource = table.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39797978
Then consider using the OpenArgs argument of the OpenForm method to pass the form what you want to use as the recordsource if not the table.  Something like:

DoCmd.OpenForm stDocName, acNormal, , , acFormEdit, acWindowNormal, "qryYourQuery"

Then use the Open event of the form to change the recordsouce appropriately:

Private sub Form_Open

     If IsNull(me.OpenArgs) = False then me.RecordSource = me.OpenArgs

End Sub
0
 

Author Comment

by:SteveL13
ID: 39797990
So this goes in the onopen event of the form:

If IsNull(me.OpenArgs) = False then me.RecordSource = me.OpenArgs

But where does this go?

DoCmd.OpenForm stDocName, acNormal, , , acFormEdit, acWindowNormal, "qryYourQuery"
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39797996
"But where does this go?"

That is how you open the form, usually from the click event of a command button on another form, or something like that.
0
 
LVL 7

Accepted Solution

by:
COACHMAN99 earned 500 total points
ID: 39798001
in calling form
populate a global variable
DoCmd.OpenForm stDocName, acNormal, , , acFormEdit, acWindowNormal


in loading form
e.g.
on load
 if var then me.recordsource = query else me.recordsource = table.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question