Solved

Invalid Bracketing of name in Insert Into qeury

Posted on 2004-08-16
12
1,613 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
  • 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 49

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
 
LVL 49

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 49

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 49

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 49

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 49

Expert Comment

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

/gustav
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now