?
Solved

Create a dynamic SQL/Query for a sub form

Posted on 2003-03-03
5
Medium Priority
?
418 Views
Last Modified: 2008-03-06
Does anyone know if there is a way to use a SQL statement for a sub form.  Or some way to use a recordset or querydef (that is not a created query object)?  Because you can use objects like queries or tables as your sourceobject for your sub form, I was hoping that I would could in some way use a SQL statement (that is created dynamically).

Any ideas anyone?  Any help would be appreciated.  Thanks.
0
Comment
Question by:NickPereza
[X]
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
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
mcallarse earned 300 total points
ID: 8059551
Can create and/or edit QueryDefs on the fly using VB(A):

Dim db
Dim qd As New QueryDef

Set db = CurrentDb

strSQL = "select * from myTable"

With qd
    .Name = "myTempQuery"
    .SQL = strSQL
End With
db.QueryDefs.Append qd

' Following to illustrate Edit only.

db.QueryDefs("myTempQuery").SQL = strSQL

Set qd = Nothing: Set db = Nothing

' Set SubForm SourceObject

mySubForm.SourceObject = "Query.myTempQuery"

--
0
 
LVL 9

Expert Comment

by:mcallarse
ID: 8059582
NOTE: If you will be using a temporary query, would suggest creating a query on main form open, using that query for all changes while the form is open, then deleting the query -- db.querydefs.delete "myTempQuery" -- on main form close. If you have multiple users accessing your database, would suggest this approach, as opposed to a single query used for all updates.
0
 
LVL 12

Expert Comment

by:nexusnation
ID: 8784128
Hi NickPereza,
This question has been abandoned and needs to be finalized (112 days since last comment).

   You can accept an answer, split the points, or get a refund. Go to
   http://www.cityofangels.com/Experts/Closing.htm for information and options.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

nexusnation
EE Cleanup Volunteer for Microsoft Access
0
 
LVL 18

Expert Comment

by:1William
ID: 8876660
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept question, points to mcallarse
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

1William
EE Cleanup Volunteer
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

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.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

752 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