Solved

Invalid Bracketing of name in Insert Into qeury

Posted on 2004-08-16
12
1,630 Views
Last Modified: 2012-08-13
Hi all,

My question is similar to the one listed in:

http://www.experts-exchange.com/Databases/MS_Access/Q_20946351.html

However, the solution there does is not accetpable to my specific situation, so I'm hoping you might be able to point me in the right direction.

I have a VB application that connects to a remote server to do various queries against the data on that server.

One of those queries goes against street names. If the user types in just a letter, say "m", then a listing of all the streets that begin with "m" should be displayed. One of the queries that is used to generate this list copies data from one database to another and is listed below:

insert into temp_streets in 'C:\Documents and Settings\P. L. Stoner\My Documents\CCPR3I\ccprtemp.mdb' select temp_tblstret.NAMESTRT as NAMESTRT, temp_tblstret.city as city, temp_tblstret.LORANGE as LORANGE, temp_tblstret.HIRANGE as HIRANGE, temp_tblstret.key as key, temp_tblstret.zip as zip, temp_tblstret.streetid as streetid from temp_tblstret WHERE (((instr(namestrt,'M') = 1) or (instr(streetid,'M') = 1)))

Both databases reside the the current user's My Documents Folder.  The problem is that when this query is fired off, I get the Invalid Bracketing of Name error. I have copied this query into Access and tried running it there, with the same error and it highlights insert into temp_streets in 'C:\Documents and Settings\P. L. Stoner\My

I believe the problem is caused by the dots (.) in the user's Name, P. L. Stoner. If I set up a different user, P L Stoner and run the application all works well.

My question is this, is there a way to properly format a user's name so that this query will work? I can't not go back to all of our users and have them change their system user name, that is simply unacceptable. I need a way to properly format so the query works as expected.

Thanks

Paul
0
Comment
Question by:PaulS_III
[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
  • 6
  • 5
12 Comments
 
LVL 17

Expert Comment

by:walterecook
ID: 11811949
I think the problem is in your syntax rather than the dots.  Access is getting confused as to what you are trying to do (as am I!)
With this:
nsert into temp_streets in 'C:\Documents and Settings\P. L. Stoner\My Documents\CCPR3I\ccprtemp.mdb'
are you trying to say that the table is in the database at 'C:\Documents and Settings\P. L. Stoner\My Documents\CCPR3I\ccprtemp.mdb'?

Walt

0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 11811956
Try when you build the SQL string to insert doublequotes around the filename:

strSQL = "insert into temp_streets in '" & Chr(34) & "C:\Documents and Settings\P. L. Stoner\My Documents\CCPR3I\ccprtemp.mdb" & Chr(34) & "' select ..."

/gustav
0
 
LVL 2

Author Comment

by:PaulS_III
ID: 11812276
Hello waltercook,

To answer your question, yes.  My exact syntax is:

gcGlobals.Col.Temp_DB.execute("insert into temp_streets in '" & gdaoTemp.name & "' select temp_tblstret.NAMESTRT as NAMESTRT, temp_tblstret.city as city, temp_tblstret.LORANGE as LORANGE, temp_tblstret.HIRANGE as HIRANGE, temp_tblstret.key as key, temp_tblstret.zip as zip, temp_tblstret.streetid as streetid from temp_tblstret WHERE (" & strStreet & ")")

the gcGlobales.Col.Temp_DB = C:\Documents and Settings\P. L. Stoner\My Documents\CCPR3I\temp_col.mdb
the gdaoTemp.name = C:\Documents and Settings\P. L. Stoner\My Documents\CCPR3I\ccprtemp.mdb
the strStreet = ((instr(namestrt,'M') = 1) or (instr(streetid,'M') = 1))

So in otherword, I want to insert records into the temp_streets table which is located in the database C:\Documents and Settings\P. L. Stoner\My Documents\CCPR3I\ccprtemp.mdb from a table named temp_tblstret located in the database C:\Documents and Settings\P. L. Stoner\My Documents\CCPR3I\temp_col.mdb which has the current connection at the time the query is executed

If I didn't say this before, then I apologize, but this works for a user directory that does not contain the dots.

Hello cactus_data,

I tried your suggestion of "insert into temp_streets in '" & Chr(34) & "C:\Documents and Settings\P. L. Stoner\My Documents\CCPR3I\ccprtemp.mdb" & Chr(34) & "' select ..." but it generated the same error.

I do appreciate all the responses thus far.  Thank you very much

Paul
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 50

Expert Comment

by:Gustav Brock
ID: 11812415
OK. Then remove the single quotes:

strSQL = "insert into temp_streets in " & Chr(34) & "C:\Documents and Settings\P. L. Stoner\My Documents\CCPR3I\ccprtemp.mdb" & Chr(34) & " select ..."

/gustav
0
 
LVL 2

Author Comment

by:PaulS_III
ID: 11812662
Still no good there gustav.

I've tried hard coding the path and database name, putting square brackets, [ ] around the full path and database name, just around the path, even just around the P. L. Stoner portion. It would seem that nothing I do to that path works.

I'm still open to suggestions

Paul
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 11818612
It seems to be the dots that confuse the SQL parser.
To circumvent that, use the connect string syntax with surrounding brackets:

  INSERT INTO
    temp_streets
  IN
    "" [DATABASE=C:\Documents and Settings\P. L. Stoner\My Documents\CCPR3I\ccprtemp.mdb;]
  SELECT
    ... etc.

/gustav
0
 
LVL 2

Author Comment

by:PaulS_III
ID: 11819325
Unless I am doing something completely wrong, your suggestion, gustav, still isn't correcting the problem.

Here is what I did:

gcGlobals.Col.Temp_DB.execute("insert into temp_streets in [DATABASE=" & gdaoTemp.name & "] select temp_tblstret.NAMESTRT as NAMESTRT, temp_tblstret.city as city, temp_tblstret.LORANGE as LORANGE, temp_tblstret.HIRANGE as HIRANGE, temp_tblstret.key as key, temp_tblstret.zip as zip, temp_tblstret.streetid as streetid from temp_tblstret WHERE (" & strStreet & ")")

That, line still generated the same error. Then I tried:

gcGlobals.Col.Temp_DB.execute("insert into temp_streets in " & chr(34) & "[DATABASE=" & gdaoTemp.name & "]" & chr(34) & " select temp_tblstret.NAMESTRT as NAMESTRT, temp_tblstret.city as city, temp_tblstret.LORANGE as LORANGE, temp_tblstret.HIRANGE as HIRANGE, temp_tblstret.key as key, temp_tblstret.zip as zip, temp_tblstret.streetid as streetid from temp_tblstret WHERE (" & strStreet & ")")

Still no good, so then I tried:

gcGlobals.Col.Temp_DB.execute("insert into temp_streets in [DATABASE=" & chr(34) & gdaoTemp.name & chr(34) & "] select temp_tblstret.NAMESTRT as NAMESTRT, temp_tblstret.city as city, temp_tblstret.LORANGE as LORANGE, temp_tblstret.HIRANGE as HIRANGE, temp_tblstret.key as key, temp_tblstret.zip as zip, temp_tblstret.streetid as streetid from temp_tblstret WHERE (" & strStreet & ")")

Still no good.


Looks like I may have to increase the points :).

I am still open for suggestions.

Thanks
0
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 350 total points
ID: 11819475
> Looks like I may have to increase the points :).

No, you just need to get it exactly right ... please carefully note the leading double doublequotes! And no quotes around or inside the brackets.

INSERT INTO
    temp_streets
  IN
    "" [DATABASE=C:\Documents and Settings\P. L. Stoner\My Documents\CCPR3I\ccprtemp.mdb;]
  SELECT
    ... etc.

/gustav
0
 
LVL 2

Author Comment

by:PaulS_III
ID: 11819917
gustav

Thank you. with a minor modification, this worked.  Here is what I ended up with:

gcGlobals.Col.Temp_DB.execute("insert into temp_streets in """"[DATABASE=" & gdaoTemp.name & "] select temp_tblstret.NAMESTRT as NAMESTRT, temp_tblstret.city as city, temp_tblstret.LORANGE as LORANGE, temp_tblstret.HIRANGE as HIRANGE, temp_tblstret.key as key, temp_tblstret.zip as zip, temp_tblstret.streetid as streetid from temp_tblstret WHERE (" & strStreet & ")")

This works splendidly.  Now this is the first time I have ever seen this and I have been working with Access and VB for about 7 years. Could you please explain what we have done and why it works?

Thanks So much for your help and patience.

Paul
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 11821631
I have only used it once and that was most for fun. Like you I have never seen a reference to this syntax.
The purpose, I guess, is to allow for specifying a full connect string including any to Access SQL special chararacters which is done by wrapping the string into the "" [..;] construction.

I'll certainly make a note on it now; this is the first example I've seen - with the dot in the path - where it turned out as the only solution.

/gustav
0
 
LVL 2

Author Comment

by:PaulS_III
ID: 11821654
Well thanks again for all your kind help and input.

I truly appreciate it.

Paul
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 11822441
Fine! You are welcome.

/gustav
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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

749 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