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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a Query with SQL string, and then show the query 1

Status
Not open for further replies.

kjv1611

New member
Jul 9, 2003
10,758
US
I haven't delved terribly deep into the usage of Queries and SQL just yet, but I think I am starting to get the hang of it. Anyway, my question is this: I have a SQL statement which creates a new query (works great so far), but I want to be able to view the query as soon as it is made (for now). Can I add something to or change something in the code I have posted here:
Code:
Private Sub cmbStatus_AfterUpdate()
    Dim strQueryName As String
    strQueryName = Me.cmbTeamLeader & " " & Me.cmbStatus

    Dim myquery As QueryDef
    Set myquery = CurrentDb.CreateQueryDef([strQueryName], _
    "SELECT tblStatusAudit.Year, tblStatusAudit.Month, " & _
    "tblStatusAudit.Director, " & _
    "tblStatusAudit.Manager, tblStatusAudit.[Team Leader], " & _
    "tblStatusAudit.Status " & _
    "FROM tblStatusAudit " & _
    "WHERE (((tblStatusAudit.[Team Leader])=[Forms]!" & _
    "[frmAuditReviewSelection]![cmbTeamLeader]) " & _
    "AND ((tblStatusAudit.Status)=[Forms]!" & _
    "[frmAuditReviewSelection]![cmbStatus]));")
??
Suggestions? I'm thinking it's probably something simple, I am just unaware of it..

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
I use the following...


Function Testmex()
Dim lcQueryName As String
lcQueryName = "qrySalary_Corrections" 'Where this is a saved query in the database.
DoCmd.OpenQuery lcQueryName
End Function

htwh,


Steve Medvid
"IT Consultant & Web Master"

Chester County, PA Residents
Please Show Your Support...
 
Thanks, that worked perfectly... I just needed this part:
Code:
    DoCmd.OpenQuery strQueryName


Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Yup, that works both in the even that creates the query, as well as in a separate button (which is my preferred method for now). That's great. I'm actually going to be sending the query to Excel or an Access Report in the long run, but this is great for testing purposes!

Thanks!

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top