Question

DAO.QueryDef

Asked by: dlmaz

I'm getting a debug error on the line qdf.SQL = strSQL stating:

Microsoft Visual Basic
Run-time error '3129':
Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'

Suggestions?

For addtional information refer to Q/A "Inner Join Query based on Input Parameter for Table Names"

Public Sub InnerJoin()
 
    Dim qdf As DAO.QueryDef
    Dim strSQL As String, strQueryName As String
        
strSQL = "SELECT " & strTblBefore & ".PPN AS BeforePPN," & strTblBefore & ".PPS AS BeforePPS," & strTblBefore & _
".PPNStatusEffDate AS BeforePPNStatusEffDate," & strTblBefore & ".JON AS BeforeJON," & strTblBefore & _
".JobTitle AS BeforeJobTitle," & strTblBefore & ".BillingCriteria AS BeforeBillCriteria," & strTblBefore & _
".ManHours AS BeforeManHrs," & strTblBefore & ".Budget AS BeforeBudget," & strTblBefore & _
".APSUnitN AS BeforeAPSUnitN," & strTblBefore & ".APSWBSN AS BeforeAPSWBSN," & strTblBefore & _
".APSDir AS BeforeAPSDir," & strTblBefore & ".APSMgr AS BeforeAPSMgr," & strTblBefore & _
".POwner AS BeforePOwner," & strTblBefore & ".CompCharge AS BeforeCompCharge," & strTblBefore & _
".ContractLbr AS BeforeContractLbr," & strTblBefore & ".AuthorizedName AS BeforeAuthName," & strTblBefore & _
".PropN AS BeforePropN," & strTblBefore & ".PLN AS BeforePLN," & strTblBefore & ".TCS AS BeforeTCS," & strTblBefore & _
".CP AS BeforeCP," & strTblBefore & ".PWPReq AS BeforePWPReq," & strTblBefore & ".SLNucQA AS BeforeSLNucQA," & strTblBefore & _
".SLProjMgr AS BeforeSLProjMgr," & strTblBefore & ".SLProgMgr AS BeforeSLProgMgr," & strTblAfter & _
".PPN AS AfterPPN," & strTblAfter & ".PPS AS AfterPPS," & strTblAfter & ".PPNStatusEffDate AS AfterPPNStatusEffDate," & strTblAfter & _
".JON AS AfterJON," & strTblAfter & ".JobTitle AS AfterJobTitle," & strTblAfter & ".BillingCriteria AS AfterBillCriteria," & strTblAfter & _
".ManHours AS AfterManHrs," & strTblAfter & ".Budget AS AfterBudget," & strTblAfter & ".APSUnitN AS AfterAPSUnitN," & strTblAfter & _
".APSWBSN AS AfterAPSWBSN," & strTblAfter & ".APSDir AS AfterAPSDir," & strTblAfter & ".APSMgr AS AfterAPSMgr," & strTblAfter & _
".POwner AS AfterPOwner," & strTblAfter & ".CompCharge AS AfterCompCharge," & strTblAfter & ".ContractLbr AS AfterContractLbr," & _
strTblAfter & ".AuthorizedName AS AfterAuthName," & strTblAfter & ".PropN AS AfterPropN," & strTblAfter & ".PLN AS AfterPLN," & _
strTblAfter & ".TCS AS AfterTCS," & strTblAfter & ".CP AS AfterCP," & strTblAfter & ".PWPReq AS AfterPWPReq," & strTblAfter & _
".SLNucQA AS AfterSLNucQA," & strTblAfter & ".SLProjMgr AS AfterSLProjMgr," & strTblAfter & ".SLProgMgr AS AfterSLProgMgr," & _
"FROM " & strTblBefore & " INNER JOIN " & strTblAfter & " ON " & strTblBefore & ".PPN = " & strTblAfter & ".PPN," & "WHERE " & strTblBefore & ".PPS AS BeforePPS," <> "X" And strTblAfter & ".PPS AS AfterPPS," <> "X"
strQueryName = "qryInnerJoinBeforeAfter"
Set qdf = CurrentDb.QueryDefs("qryInnerJoinBeforeAfter")
qdf.SQL = strSQL
Set qdf = Nothing
 
 Debug.Print strSQL
    
End Sub

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-07-09 at 15:50:33ID24558504
Topics

Microsoft Access Database

,

Access Coding/Macros

Participating Experts
5
Points
500
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Help with INNER JOIN Please
    HI All. Here is my SQL statement: strSQL = "SELECT OrderDetails.ProductNumber, Products.ItemDownloadLocation FROM OrderDetails INNER JOIN Products ON OrderDetails.ProductNumber = Products.ItemProductNumber WHERE OrderDetails.OrderID = "&getorder&"&quo...
  2. Problems with INNER JOIN query
    I'm making a web access for my MS Access database (relational database) with ASP. all works well except that (I think) my SQL statement is not being executed correctly. It has something to do with the INNER JOIN (this is the first time I've used an inner join)I think, becaus...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: cwood-wm-comPosted on 2009-07-09 at 16:00:53ID: 24819061

There is something very strange about your SQL string. When I dimension the strTblBefore and strTblAfter as strings and give them values, then put Debug.Print strSQL after strSQL = "SELECT " & ..., I get True instead of a string.

Public Sub InnerJoin()
 
    Dim qdf As DAO.QueryDef
    Dim strSQL As String, strQueryName As String
    Dim strTblBefore As String, strTblAfter As String
    strTblBefore = "strTblBefore"
    strTblAfter = "strTblAfter"
strSQL = "SELECT " & strTblBefore & ".PPN AS BeforePPN," & strTblBefore & ".PPS AS BeforePPS," & strTblBefore & _
".PPNStatusEffDate AS BeforePPNStatusEffDate," & strTblBefore & ".JON AS BeforeJON," & strTblBefore & _
".JobTitle AS BeforeJobTitle," & strTblBefore & ".BillingCriteria AS BeforeBillCriteria," & strTblBefore & _
".ManHours AS BeforeManHrs," & strTblBefore & ".Budget AS BeforeBudget," & strTblBefore & _
".APSUnitN AS BeforeAPSUnitN," & strTblBefore & ".APSWBSN AS BeforeAPSWBSN," & strTblBefore & _
".APSDir AS BeforeAPSDir," & strTblBefore & ".APSMgr AS BeforeAPSMgr," & strTblBefore & _
".POwner AS BeforePOwner," & strTblBefore & ".CompCharge AS BeforeCompCharge," & strTblBefore & _
".ContractLbr AS BeforeContractLbr," & strTblBefore & ".AuthorizedName AS BeforeAuthName," & strTblBefore & _
".PropN AS BeforePropN," & strTblBefore & ".PLN AS BeforePLN," & strTblBefore & ".TCS AS BeforeTCS," & strTblBefore & _
".CP AS BeforeCP," & strTblBefore & ".PWPReq AS BeforePWPReq," & strTblBefore & ".SLNucQA AS BeforeSLNucQA," & strTblBefore & _
".SLProjMgr AS BeforeSLProjMgr," & strTblBefore & ".SLProgMgr AS BeforeSLProgMgr," & strTblAfter & _
".PPN AS AfterPPN," & strTblAfter & ".PPS AS AfterPPS," & strTblAfter & ".PPNStatusEffDate AS AfterPPNStatusEffDate," & strTblAfter & _
".JON AS AfterJON," & strTblAfter & ".JobTitle AS AfterJobTitle," & strTblAfter & ".BillingCriteria AS AfterBillCriteria," & strTblAfter & _
".ManHours AS AfterManHrs," & strTblAfter & ".Budget AS AfterBudget," & strTblAfter & ".APSUnitN AS AfterAPSUnitN," & strTblAfter & _
".APSWBSN AS AfterAPSWBSN," & strTblAfter & ".APSDir AS AfterAPSDir," & strTblAfter & ".APSMgr AS AfterAPSMgr," & strTblAfter & _
".POwner AS AfterPOwner," & strTblAfter & ".CompCharge AS AfterCompCharge," & strTblAfter & ".ContractLbr AS AfterContractLbr," & _
strTblAfter & ".AuthorizedName AS AfterAuthName," & strTblAfter & ".PropN AS AfterPropN," & strTblAfter & ".PLN AS AfterPLN," & _
strTblAfter & ".TCS AS AfterTCS," & strTblAfter & ".CP AS AfterCP," & strTblAfter & ".PWPReq AS AfterPWPReq," & strTblAfter & _
".SLNucQA AS AfterSLNucQA," & strTblAfter & ".SLProjMgr AS AfterSLProjMgr," & strTblAfter & ".SLProgMgr AS AfterSLProgMgr," & _
"FROM " & strTblBefore & " INNER JOIN " & strTblAfter & " ON " & strTblBefore & ".PPN = " & strTblAfter & ".PPN," & "WHERE " & strTblBefore & ".PPS AS BeforePPS," <> "X" And strTblAfter & ".PPS AS AfterPPS," <> "X"
 
'======== ADDED ========
Debug.Print strSQL
'=======================
 
strQueryName = "qryInnerJoinBeforeAfter"
Set qdf = CurrentDb.QueryDefs("qryInnerJoinBeforeAfter")
qdf.Sql = strSQL
Set qdf = Nothing
 
 Debug.Print strSQL
    
End Sub
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:

Select allOpen in new window

 

by: capricorn1Posted on 2009-07-09 at 16:11:55ID: 24819145

try this

strSQL = "SELECT " & strTblBefore & ".PPN AS BeforePPN," & strTblBefore & ".PPS AS BeforePPS," & strTblBefore & _
".PPNStatusEffDate AS BeforePPNStatusEffDate," & strTblBefore & ".JON AS BeforeJON," & strTblBefore & _
".JobTitle AS BeforeJobTitle," & strTblBefore & ".BillingCriteria AS BeforeBillCriteria," & strTblBefore & _
".ManHours AS BeforeManHrs," & strTblBefore & ".Budget AS BeforeBudget," & strTblBefore & _
".APSUnitN AS BeforeAPSUnitN," & strTblBefore & ".APSWBSN AS BeforeAPSWBSN," & strTblBefore & _
".APSDir AS BeforeAPSDir," & strTblBefore & ".APSMgr AS BeforeAPSMgr," & strTblBefore & _
".POwner AS BeforePOwner," & strTblBefore & ".CompCharge AS BeforeCompCharge," & strTblBefore & _
".ContractLbr AS BeforeContractLbr," & strTblBefore & ".AuthorizedName AS BeforeAuthName," & strTblBefore & _
".PropN AS BeforePropN," & strTblBefore & ".PLN AS BeforePLN," & strTblBefore & ".TCS AS BeforeTCS," & strTblBefore & _
".CP AS BeforeCP," & strTblBefore & ".PWPReq AS BeforePWPReq," & strTblBefore & ".SLNucQA AS BeforeSLNucQA," & strTblBefore & _
".SLProjMgr AS BeforeSLProjMgr," & strTblBefore & ".SLProgMgr AS BeforeSLProgMgr," & strTblAfter & _
".PPN AS AfterPPN," & strTblAfter & ".PPS AS AfterPPS," & strTblAfter & ".PPNStatusEffDate AS AfterPPNStatusEffDate," & strTblAfter & _
".JON AS AfterJON," & strTblAfter & ".JobTitle AS AfterJobTitle," & strTblAfter & ".BillingCriteria AS AfterBillCriteria," & strTblAfter & _
".ManHours AS AfterManHrs," & strTblAfter & ".Budget AS AfterBudget," & strTblAfter & ".APSUnitN AS AfterAPSUnitN," & strTblAfter & _
".APSWBSN AS AfterAPSWBSN," & strTblAfter & ".APSDir AS AfterAPSDir," & strTblAfter & ".APSMgr AS AfterAPSMgr," & strTblAfter & _
".POwner AS AfterPOwner," & strTblAfter & ".CompCharge AS AfterCompCharge," & strTblAfter & ".ContractLbr AS AfterContractLbr," & _
strTblAfter & ".AuthorizedName AS AfterAuthName," & strTblAfter & ".PropN AS AfterPropN," & strTblAfter & ".PLN AS AfterPLN," & _
strTblAfter & ".TCS AS AfterTCS," & strTblAfter & ".CP AS AfterCP," & strTblAfter & ".PWPReq AS AfterPWPReq," & strTblAfter & _
".SLNucQA AS AfterSLNucQA," & strTblAfter & ".SLProjMgr AS AfterSLProjMgr," & strTblAfter & ".SLProgMgr AS AfterSLProgMgr " & _
"FROM " & strTblBefore & " INNER JOIN " & strTblAfter & " ON " & strTblBefore & ".PPN = " & strTblAfter & ".PPN" & " WHERE " & strTblBefore & ".PPS <> ""X"" And " & strTblAfter & ".PPS <> ""X"""

strQueryName = "qryInnerJoinBeforeAfter"
Set qdf = CurrentDb.QueryDefs("qryInnerJoinBeforeAfter")
qdf.SQL = strSQL
Set qdf = Nothing

 Debug.Print strSQL

 

by: mbizupPosted on 2009-07-09 at 16:22:38ID: 24819224

For starters, your syntax with the line continuation characters (Underscores) is incorrect.

I've fixed a few lines for you to show you the correct syntax (Underscore at the end, ampersand at the beginning of the next line):
 
strSQL = "SELECT " & strTblBefore & ".PPN AS BeforePPN," & strTblBefore & ".PPS AS BeforePPS," & strTblBefore _
 & ".PPNStatusEffDate AS BeforePPNStatusEffDate," & strTblBefore & ".JON AS BeforeJON," & strTblBefore _
 & ".JobTitle AS BeforeJobTitle," & strTblBefore & ".BillingCriteria AS BeforeBillCriteria," & strTblBefore _
 & ".ManHours AS BeforeManHrs," & strTblBefore & ".Budget AS BeforeBudget," & strTblBefore _
 & ".APSUnitN AS BeforeAPSUnitN," & strTblBefore & ".APSWBSN AS BeforeAPSWBSN," & strTblBefore

Also, you need to define strTblBefore and strTblAfter (as shown in the previous post)

 

by: mbizupPosted on 2009-07-09 at 16:24:02ID: 24819236

Sorry cap,

I didn't refresh the screen.

cap's syntax works as well.

(Ignore my previous post)

 

by: mbizupPosted on 2009-07-09 at 17:01:56ID: 24819446

dlmaz,

For the record, it's nothing to do with the line continuation characters. I'm set in my ways of doing things, so at first glance your syntax looked wrong to me (that part of the syntax in the original post is definitely correct - my remark to the contrary was wrong).

This was the original end of your sql string:
".PPS AS BeforePPS," <> "X" And strTblAfter & ".PPS AS AfterPPS," <> "X"

Cap made a great catch on this one. The change he made was very subtle:


strTblBefore & ".PPS <> ""X"" And " & strTblAfter & ".PPS <> ""X"""

He rearranged the quotes a bit dropping the quotes before the <> and adding quotes around the X's. This embedded the X in the SQL string.

Before that, the SQL string was effectively a boolean expression that checked two conditions:
1. The bulk of your SQL string <> 'X'
2. "someTableName.PPS AS AfterPPS," <> "X"

Both of these conditions are true since neither of these strings was literally 'X'. That's why the SQL string evaluated to TRUE, per the first comment.

No points for this comment please - it was an excellent find on cap's part, but worthy of an explanation.

 

by: dlmazPosted on 2009-07-09 at 17:04:46ID: 24819456

Thank you for the quick responses, however after using the code as provided by capricorn1, I now get this error:

Run-time error '3075':
Syntax error (missing operator) in query expression '.PPN'

What I am trying to accomplish is to get an inner join query to run based upon input on the table names that are created by the user (see note below).

Please, note the SQL is based upon the following:

Public Function CreateTable()

    Dim sSql As String
    Dim sTable
   
    sTable = InputBox("Enter Table Name", "Table Creation")
    If Trim$(Nz(sTable, "")) = "" Then
        MsgBox "Must specify table name"
    Else
        sSql = "SELECT PPN, PPS, PPNStatusEffDate, JON, JobTitle, BillingCriteria, ManHours, Budget, APSUnitN, APSWBSN, APSDir, APSMgr, POwner, CompCharge, ContractLbr, AuthorizedName, PropN, PLN, TCS, CP, PWPReq, SLNucQA, SLProjMgr, SLProgMgr INTO [" & sTable & "] FROM qryBeforeAfter"

        Debug.Print sSql

        CurrentDb.Execute sSql, dbFailOnError
    End If
End Function

 

by: capricorn1Posted on 2009-07-09 at 17:13:00ID: 24819497


dlmaz,

in your query that you build, you have specified
" & strTblBefore & ".PPN AS BeforePPN

and
" & strTblAfter & ".PPN AS AfterPPN

 

by: LPurvisPosted on 2009-07-09 at 17:41:54ID: 24819597

Just to mention - readability is a wonderful thing in development.
It helps you support your own application, which helps you make your application's quality better.
While I don't believe in it at the expense of performance or functionality, when there's nothing to lose then readability every time! ;-)

A couple of table aliases and it's much simpler.

strSQL = "SELECT B.PPN AS BeforePPN, B.PPS AS BeforePPS," & _
"B.PPNStatusEffDate AS BeforePPNStatusEffDate, B.JON AS BeforeJON," & _
"B.JobTitle AS BeforeJobTitle, B.BillingCriteria AS BeforeBillCriteria," & _
"B.ManHours AS BeforeManHrs, B.Budget AS BeforeBudget," & _
"B.APSUnitN AS BeforeAPSUnitN, B.APSWBSN AS BeforeAPSWBSN," & _
"B.APSDir AS BeforeAPSDir, B.APSMgr AS BeforeAPSMgr," & _
"B.POwner AS BeforePOwner, B.CompCharge AS BeforeCompCharge," & _
"B.ContractLbr AS BeforeContractLbr, B.AuthorizedName AS BeforeAuthName," & _
"B.PropN AS BeforePropN, B.PLN AS BeforePLN, B.TCS AS BeforeTCS," & _
"B.CP AS BeforeCP, B.PWPReq AS BeforePWPReq, B.SLNucQA AS BeforeSLNucQA," & _
"B.SLProjMgr AS BeforeSLProjMgr, B.SLProgMgr AS BeforeSLProgMgr," & _
"A.PPN AS AfterPPN, A.PPS AS AfterPPS, A.PPNStatusEffDate AS AfterPPNStatusEffDate," & _
"A.JON AS AfterJON, A.JobTitle AS AfterJobTitle, A.BillingCriteria AS AfterBillCriteria," & _
"A.ManHours AS AfterManHrs, A.Budget AS AfterBudget, A.APSUnitN AS AfterAPSUnitN," & _
"A.APSWBSN AS AfterAPSWBSN, A.APSDir AS AfterAPSDir, A.APSMgr AS AfterAPSMgr," & _
"A.POwner AS AfterPOwner, A.CompCharge AS AfterCompCharge, A.ContractLbr AS AfterContractLbr," & _
"A.AuthorizedName AS AfterAuthName, A.PropN AS AfterPropN, A.PLN AS AfterPLN," & _
"A.TCS AS AfterTCS, A.CP AS AfterCP, A.PWPReq AS AfterPWPReq," & _
"A.SLNucQA AS AfterSLNucQA, A.SLProjMgr AS AfterSLProjMgr, A.SLProgMgr AS AfterSLProgMgr " & _
"FROM " & strTblBefore & " B INNER JOIN " & strTblAfter & " A ON B.PPN = A.PPN WHERE B.PPS <> 'X' And A.PPS <> 'X'"

 

by: GRayLPosted on 2009-07-10 at 07:53:02ID: 24823908

Miriam:  I've had & at the end of a line on countless occasions.

 

by: dlmazPosted on 2009-07-15 at 12:39:31ID: 24863248

Please, excuse the delayed response but I've had other issues at work that took priority over this until now. Reviewing the comments since my last post, I still haven't been able to resolve this issue.

Now, there was one module created to allow the user to name the table being created from essentially a Make Table query.

The second module that I'm working on will run the Inner Join query based upon the 2 table names supplied by the user.

For example, the user specifies a table name of Smith and another table name of Jones. When the Inner Join query is run, it should ask the user which table name will be considered tblBefore? and which table name will be considered tblAfter?

Hopefully, this will help clarify what it is I am trying to accomplish. If it's still not clear or if the code used so far will not accomplish this, please, feel free to advise me. Thank you!

 

by: LPurvisPosted on 2009-07-15 at 15:39:36ID: 24864866

I'm not entirely clear. Which part are you still struggling with? Asking the user? Using their entries? The SQL itself should be OK - no?

 

by: dlmazPosted on 2009-07-16 at 07:34:53ID: 24869520

Using the attached, I'm still getting a Run-time error 'syntax error (missing operator) in query expression '.PPN'.'

Also, I discovered yesterday afternoon that when the SQL did work with input on the table names, the query is not using the data from those tables anyway.

I just don't seem to get it!

I don't know what I'm doing wrong or if I'm making it more complicated than it should be.

ublic Sub InnerJoin()
 
    Dim qdf As DAO.QueryDef
    Dim strSQL As String, strQueryName As String
        
strSQL = "SELECT " & strTblBefore & ".PPN AS BeforePPN," & strTblBefore & ".PPS AS BeforePPS," & strTblBefore & _
".PPNStatusEffDate AS BeforePPNStatusEffDate," & strTblBefore & ".JON AS BeforeJON," & strTblBefore & _
".JobTitle AS BeforeJobTitle," & strTblBefore & ".BillingCriteria AS BeforeBillCriteria," & strTblBefore & _
".ManHours AS BeforeManHrs," & strTblBefore & ".Budget AS BeforeBudget," & strTblBefore & _
".APSUnitN AS BeforeAPSUnitN," & strTblBefore & ".APSWBSN AS BeforeAPSWBSN," & strTblBefore & _
".APSDir AS BeforeAPSDir," & strTblBefore & ".APSMgr AS BeforeAPSMgr," & strTblBefore & _
".POwner AS BeforePOwner," & strTblBefore & ".CompCharge AS BeforeCompCharge," & strTblBefore & _
".ContractLbr AS BeforeContractLbr," & strTblBefore & ".AuthorizedName AS BeforeAuthName," & strTblBefore & _
".PropN AS BeforePropN," & strTblBefore & ".PLN AS BeforePLN," & strTblBefore & ".TCS AS BeforeTCS," & strTblBefore & _
".CP AS BeforeCP," & strTblBefore & ".PWPReq AS BeforePWPReq," & strTblBefore & ".SLNucQA AS BeforeSLNucQA," & strTblBefore & _
".SLProjMgr AS BeforeSLProjMgr," & strTblBefore & ".SLProgMgr AS BeforeSLProgMgr," & strTblAfter & _
".PPN AS AfterPPN," & strTblAfter & ".PPS AS AfterPPS," & strTblAfter & ".PPNStatusEffDate AS AfterPPNStatusEffDate," & strTblAfter & _
".JON AS AfterJON," & strTblAfter & ".JobTitle AS AfterJobTitle," & strTblAfter & ".BillingCriteria AS AfterBillCriteria," & strTblAfter & _
".ManHours AS AfterManHrs," & strTblAfter & ".Budget AS AfterBudget," & strTblAfter & ".APSUnitN AS AfterAPSUnitN," & strTblAfter & _
".APSWBSN AS AfterAPSWBSN," & strTblAfter & ".APSDir AS AfterAPSDir," & strTblAfter & ".APSMgr AS AfterAPSMgr," & strTblAfter & _
".POwner AS AfterPOwner," & strTblAfter & ".CompCharge AS AfterCompCharge," & strTblAfter & ".ContractLbr AS AfterContractLbr," & _
strTblAfter & ".AuthorizedName AS AfterAuthName," & strTblAfter & ".PropN AS AfterPropN," & strTblAfter & ".PLN AS AfterPLN," & _
strTblAfter & ".TCS AS AfterTCS," & strTblAfter & ".CP AS AfterCP," & strTblAfter & ".PWPReq AS AfterPWPReq," & strTblAfter & _
".SLNucQA AS AfterSLNucQA," & strTblAfter & ".SLProjMgr AS AfterSLProjMgr," & strTblAfter & ".SLProgMgr AS AfterSLProgMgr " & _
"FROM " & strTblBefore & " INNER JOIN " & strTblAfter & " ON " & strTblBefore & ".PPN = " & strTblAfter & ".PPN" & " WHERE " & strTblBefore & ".PPS <> ""X"" And " & strTblAfter & ".PPS <> ""X"""
 
strQueryName = "qryInnerJoinBeforeAfter"
Set qdf = CurrentDb.QueryDefs("qryInnerJoinBeforeAfter")
qdf.SQL = strSQL
Set qdf = Nothing
 
 Debug.Print strSQL
 
    
End Sub

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:

Select allOpen in new window

 

by: cwood-wm-comPosted on 2009-07-16 at 07:55:32ID: 24869756

Replace lines 27 through 29 with the code in the snippet.
-Chuck

' turn off error handling
On Error Resume Next
    With CurrentDb
        ' delete any the query if it exists
        .QueryDefs.Delete strQueryName
        DoEvents
' turn error handling back on
On Error GoTo 0
        ' create a new query
        Set qdf = .CreateQueryDef(strQueryName)
        DoEvents
        ' set the sql of the new query
        qdf.Sql = strSQL
        DoEvents
        ' run the query,
        qdf.Execute
        DoEvents
        ' delete the query
        .QueryDefs.Delete strQueryName
        DoEvents
    End With
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:

Select allOpen in new window

 

by: dlmazPosted on 2009-07-16 at 08:12:13ID: 24869949

Thank you for the quick response but now I get Run-time error '3065'; Cannot execute a select query. The query itself "qryInnerJoinBeforeAfter" is an inner join query....?

 

by: cwood-wm-comPosted on 2009-07-16 at 08:24:21ID: 24870079

Sorry, I used some code that runs an action query. Remove these four lines from the code I previously posted and that should eliminate the error.

        ' run the query,
        qdf.Execute
        DoEvents
        ' delete the query
        .QueryDefs.Delete strQueryName
        DoEvents
                                              
1:
2:
3:
4:
5:
6:

Select allOpen in new window

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...