473,797 Members | 2,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CreateQueryDef failure

3 New Member
I have several queries that I create from SQL statements using Currentdb.Creat eQueryDef in one of these cases the code breaks and refuses to create the query giving me a:
Run-time error 3131. Syntax error in FROM clause. I'm supposing that it won't create the query because it analyzes the SQL string and determines that there is a syntax error in the FROM clause of the query I am trying to create.

The odd thing is that if I take this same SQL string and paste it into the Access QBE it runs just fine. Does anyone have a clue as to what might be wrong. Below is both the "offending" line of code as well as the entire function containing the SQL statement.

==== Function below ========

Expand|Select|Wrap|Line Numbers
  1. Function AggAlloc()
  2. Dim db As Database, strSQL As String
  3. Set db = CurrentDb
  4.  
  5. strSQL = "SELECT HR_Subset.[Person Number], HR_Subset.[Company/Cost Center Code/Name], HR_Subset.[Band], " & _
  6. "HR_Subset.[First Name], HR_Subset.[Last Name], HR_Subset.FullName, HR_Subset.[Middle Name], " & _
  7. "HR_Subset.[Preferred Name], HR_Subset.[NB ID], HR_Subset.[Associate E-mail address], HR_Subset.[Work Phone], " & _
  8. "HR_Subset.[Work Fax], HR_Subset.[Mail Code], HR_Subset.[Work Address 1], HR_Subset.[Work Address 2], " & _
  9. "HR_Subset.[Work City], HR_Subset.[Work County], HR_Subset.[Work State], HR_Subset.[Work Zip], " & _
  10. "HR_Subset.[Work Country], qryManagers.[First Name] AS [Manager First Name], qryManagers.[Last Name] " & _
  11. "AS [Manager Last Name], qryManagers.[Middle Name] AS [Manager Middle Name], qryManagers.[Associate E-mail address] " & _
  12. "AS [Manager E-mail Address], qryManagers.[Work Phone] AS [Manager Work Phone], qryManagers.[Mail Code] " & _
  13. "AS [Manager Mail Code], qryManagers.[Work Address 1] AS [Manager Work Address 1], qryManagers.[Work Address 2] " & _
  14. "AS [Manager Work Address 2], qryManagers.[Work City] AS [Manager Work City], qryManagers.[Work County]" & _
  15. "AS [Manager Work County], qryManagers.[Work State] AS [Manager Work State], qryManagers.[Work Zip] AS " & _
  16. "[Manager Work Zip], HR_Subset.[Job Code], HR_Subset.[Job Title], tblAllocations_Crosstab.[200607], " & _
  17. "tblAllocations_Crosstab.[200608], tblAllocations_Crosstab.[200609], tblAllocations_Crosstab.[200610], " & _
  18. "tblAllocations_Crosstab.[200611], tblAllocations_Crosstab.[200612], tblAllocations_Crosstab.[200701], " & _
  19. "tblAllocations_Crosstab.[200702], tblAllocations_Crosstab.[200703], tblAllocations_Crosstab.[200704], " & _
  20. "tblAllocations_Crosstab.[200705], tblAllocations_Crosstab.[200706], tblAllocations_Crosstab.[200707], " & _
  21. "tblAllocations_Crosstab.[200708], tblAllocations_Crosstab.[200709], tblAllocations_Crosstab.[200710], " & _
  22. "tblAllocations_Crosstab.[200711], tblAllocations_Crosstab.[200712] FROM (qryManagers RIGHT JOIN HR_Subset " & _
  23. "ON qryManagers.[Person Number] = HR_Subset.[Person Number]) LEFT JOIN tblAllocations_Crosstab" & _
  24. "ON HR_Subset.[NB ID] = tblAllocations_Crosstab.[Resource ID]"
  25. If QueryExists("qryReport_AggAlloc") Then DoCmd.DeleteObject acQuery, "qryReport_AggAlloc"
  26. db.CreateQueryDef "qryReport_AggAlloc", strSQL '<----Problem line
  27. Set db = Nothing
  28. End Function

Thanks,
Expat
Aug 1 '06 #1
8 3534
Expat
3 New Member
Well....it's been more than half a day since I posted my question and no one has responded. I'm new to this site so I'm guessing that not many people use this site, no one knows the answer to my question or....?

At any rate no one needs to bother answering my question because I have the answer which i will share with you in case the same ever happens to you in the future.

The reason my createQueryDef failed was because, indeed as the Error message stated, there was an error in the FROM portion of my SQL statement. it was merely a problem of having used a couple of line continuation characters in such a place so as to introduce too many spaces between certain elements of the statement. the solution was to simply put the whole FROM portion of the SQL Statement onto one line, thereby avoiding syntax errors.
Aug 2 '06 #2
Tuckerman
1 New Member
1.) Add one space to the start of each and every line.
to avoid there being NO space between TWO REAL words of the SQL

for example in your SQL
tblAllocations_ Crosstab" & _
"ON HR_Subset.[NB ID] = tblAllocations_ Crosstab.[Resource ID]"
There is no space between the end of crosstabs and the start of next line.

2.) prior to executing the SQL do a ......debug.pri nt SQLstr . then cntl-g to see the printout. copy and past into NOTEPAD with a large font and look at it carefully for two words that a NOT seperated by a space. MAKE SURE that notepad is set to UNCHECK wordwrap
Aug 3 '06 #3
Expat
3 New Member
Good idea, Tuckerman, to paste into Notepad with a large font. I almost never have a problem with doing this because I usually do make sure that there are enough spaces between words in the statement but your suggestion to paste it from the immediate window into Notepad makes it easier still to see that there are indeed the proper spaces between elements of the SQL statement.

Thanks for your reply and suggestion.

EXPAT

1.) Add one space to the start of each and every line.
to avoid there being NO space between TWO REAL words of the SQL

for example in your SQL
tblAllocations_ Crosstab" & _
"ON HR_Subset.[NB ID] = tblAllocations_ Crosstab.[Resource ID]"
There is no space between the end of crosstabs and the start of next line.

2.) prior to executing the SQL do a ......debug.pri nt SQLstr . then cntl-g to see the printout. copy and past into NOTEPAD with a large font and look at it carefully for two words that a NOT seperated by a space. MAKE SURE that notepad is set to UNCHECK wordwrap
Aug 3 '06 #4
babyspring
4 New Member
I also encountered the same problem and tried adding space but it still didn't work! Can anyone spot my mistake, please?
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSearch_Change()
  2.  
  3. If txtSearch.Text = vbNullString Then
  4.     Set rstSearch = dbsNormah.OpenRecordset("Children General Record", dbOpenTable)
  5.  
  6. Else
  7.  
  8. Set rstSearch = dbsNormah.OpenRecordset("Select * from Children General Record where surname = ' " & txtSearch.Text & " ' " & " & '*'")
  9.  
  10. End If
  11.  
  12. list
  13.  
  14. End Sub 
Dec 8 '06 #5
NeoPa
32,579 Recognized Expert Moderator MVP
Please do not Hijack another thread for your question.
For an answer to your question you need to post a new thread for it.
However, I notice that Tuckerman's advice would also help you to resolve your problem.
Remember also, to put [] around any table or field name with embedded spaces.
Dec 8 '06 #6
babyspring
4 New Member
I'm really sorry but I thought since it is about the same topic, it will be easier if everything is grouped together.

I'll post a new post :D Thank you
Dec 9 '06 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1.  LEFT JOIN tblAllocations_Crosstab " & _
  2. "ON HR_Subset.[NB ID] = tblAllocations_Crosstab.[Resource ID]"
  3.  
Expat,

I think you were missing a space between tblAllocations_ Crosstab and ON.

Mary
Dec 9 '06 #8
NeoPa
32,579 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1.  LEFT JOIN tblAllocations_Crosstab " & _
  2. "ON HR_Subset.[NB ID] = tblAllocations_Crosstab.[Resource ID]"
  3.  
Expat,

I think you were missing a space between tblAllocations_ Crosstab and ON.

Mary
Mary,

I know you're half-asleep and hung-over still - but he had an answer in early August! lol.
Don't worry - I almost did exactly the same thing when I was fully awake :(.

Babyspring,

You make a fair point and I hear where you're coming from.
In this case though, the problems don't seem to be similar enough to make it a good idea.
I haven't checked all the new threads yet but if you've posted then we'll get you an answer if we can.
Alternatively, I didn't want to answer you before directly, but certainly there are ideas posted as answers in this thread that should help you if you think about it.

-Adrian.
Dec 9 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
8862
by: Andrew | last post by:
Hi: I run into the following problem where I would use CreateQuerydef to create a new Table and then use "Execute" to execute the statement. However, I keep getting an error message saying that the table already exists! (Error 3010 Table already exists). But I made sure that the table were dropped before I executed the statement and I went into the database to check that the table was deleted before I ran the "execute" statement. Here...
3
4814
by: priscilla.jenkins | last post by:
Alright, I'm really new to SQL and VBA and all this, so I might be completely off course...but just tell me. I know C and Assembly, but that doesn't help me much here. I'm trying to create a module that creates 5 queries (that a report is based on) based on a table that the user defines. My tables are named by date (not my choice), for example: -ArchivedActions05-20-05 Everything involving that seems fine. I'm getting a syntax error...
2
2935
by: oh4real | last post by:
Howdy all. I have pretty much NO VB/Access coding experience, but am forced to come up with a generic script/process for users with varying database designs and varying levels of expertise to use and integrate into their Dbs. Following is my script and is launched On_Open event. The script determines someone's desired upload class (test, archive or recent), executes a specific query based on that info, then writes the query results to a...
6
2494
by: rahuldev999 | last post by:
Hi I am beginner in the access project. can anyone suggest how to deal with this " Set rq = Db.CreateQueryDef("r_temp_rslt_research", strSql)" in the below code.As its a MDB application which needs to be converted into ADP. Any kind of help would be highly appreciated. Below is the snippet of code: Dim Db As DAO.Database
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10468
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10245
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10205
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9063
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.