Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244

    What's wrong!


    What's wrong with this query?
    HTML Code:
    Dim strSourcePath As String
       strSourcePath = "C:\01 - Service Contracts-TEST\Service Contracts Back-End.accdb"
       
       'get only logged in user allowed contracts data
       
       Dim strSQL As String
       strSQL = "INSERT INTO tblItem_Local"
       strSQL = strSQL + " SELECT tblItem.*"
       strSQL = strSQL + " FROM  [" & strSourcePath & "].tblItem"
       strSQL = strSQL + " WHERE (([" & strSourcePath & "].tblItem.ContractNo) "
       strSQL = strSQL + " In ((SELECT  UserAccess_T.[ContractNo]"
       strSQL = strSQL + " FROM UserAccess_T WHERE  [UserAccess_T].[F_KOCID]) = " & TempVars!gUserID & "));"
       CurrentDb.Execute (strSQL)
    Error Msg: '' is not a valid name. Make sure that it does not include invalid charactors or punchuation that is not too long.

  2. #2
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    You can write SQL a little bit differently when using CurrentDb.Execute. Below is a link for syntax. For one you don't need the "tblItem." portion. You can just "SELECT * FROM...". Try CurrentDb.Execute strSQL, dbFailOnError. I have never used () when using CurrentDb.Execute.

    http://bytes.com/topic/access/insigh...access-queries

  3. #3
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    Hi jgelpi16,

    The CurrentDb.Execute strSQL, dbFailOnError gives the same error.

    Actually the "tblItem." is not a local table. it is in another database in:

    strSourcePath = "C:\01 - Service Contracts-TEST\Service Contracts Back-End.accdb"

    This is not a link table also, I want to reffer the tblItem.ContractNo field in IN(Select Statment):
    WHERE (([" & strSourcePath & "].tblItem.ContractNo)

    But can't figure it out where is the mess.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Is gUserID text or number? If text need apostrophe delimiters. Otherwise, looks okay.

    Step debug. Debug.Print strSQL. Did the sql compose correctly?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    Hi, June!
    gUserID is numeric value so it doesn't need the apostrophe.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    jgelpi16 has a point, probably don't need to repeat the path in the WHERE clause.

    Did step debug and Debug.Print reveal anything?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    I use the break point on the code and found some parentheses missing problems, then syntax error message, which were corrected, lastly this error message

    Error Msg: '' is not a valid name. Make sure that it does not include invalid characters or punctuation that is not too long.
    I am not sure if it will give reference to the desire table’s field without giving the path in WHERE clause.

  8. #8
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    I think there may be one too many ")"? Here is what you posted...

    Code:
    Dim strSQL As String
       strSQL = "INSERT INTO tblItem_Local"
       strSQL = strSQL + " SELECT tblItem.*"
       strSQL = strSQL + " FROM  [" & strSourcePath & "].tblItem"
       strSQL = strSQL + " WHERE (([" & strSourcePath & "].tblItem.ContractNo) "
       strSQL = strSQL + " In ((SELECT  UserAccess_T.[ContractNo]"
       strSQL = strSQL + " FROM UserAccess_T WHERE  [UserAccess_T].[F_KOCID]) = " & TempVars!gUserID & "));"
       CurrentDb.Execute (strSQL)
    Is that closed paren supposed to be there?

  9. #9
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Quote Originally Posted by khalid View Post

    Error Msg: '' is not a valid name. Make sure that it does not include invalid characters or punctuation that is not too long.
    I am not sure if it will give reference to the desire table’s field without giving the path in WHERE clause.
    I've received this error message when I have begun to have corruption issues. Have you ran compact & repair on both DBs?

  10. #10
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    Hi, jgelpi16,

    Removing )
    FROM UserAccess_T WHERE [UserAccess_T].[F_KOCID]) =

    gives syntax error.

  11. #11
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    I compact and repair both the dbs, same error...

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    There is an even number parens but maybe that pair is not needed.

    Try the shorter WHERE clause, without the source string and table, just the field.

    strSQL = strSQL & " WHERE ContractNo"
    strSQL = strSQL & " In (SELECT UserAccess_T.[ContractNo]"
    strSQL = strSQL & " FROM UserAccess_T WHERE [UserAccess_T].[F_KOCID] = " & TempVars!gUserID & ");"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    Astonishing error. The first time I am facing

  14. #14
    khalid's Avatar
    khalid is offline MS-Access Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2010
    Location
    Kuwait
    Posts
    244
    Quote Originally Posted by June7 View Post
    jgelpi16, there is an even number parens but maybe that pair is not needed.

    Try the shorter WHERE clause, without the source string and table, just the field.

    strSQL = strSQL & " WHERE ContractNo"
    strSQL = strSQL & " In (SELECT UserAccess_T.[ContractNo]"
    strSQL = strSQL & " FROM UserAccess_T WHERE [UserAccess_T].[F_KOCID] = " & TempVars!gUserID & ");"

    Great! that's it.

    Thank you very much both of you the above code did the tricks.

    Code:
       Dim strSQL As String
       strSQL = "INSERT INTO tblItem_Local"
       strSQL = strSQL + " SELECT tblItem.*"
       strSQL = strSQL + " FROM  [" & strSourcePath & "].tblItem"
       strSQL = strSQL + " WHERE ContractNo"
       strSQL = strSQL + " In (SELECT UserAccess_T.[ContractNo]"
       strSQL = strSQL + " FROM UserAccess_T WHERE [UserAccess_T].[F_KOCID] = " & TempVars!gUserID & ");"
       
       CurrentDb.Execute strSQL, dbFailOnError
    Actually June7 is right, there is no need for the path again in the WHERE clause.

    Thanks dude!

  15. #15
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Glad you got it worked out!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. can't figure out what i'm doing wrong
    By m0use in forum Queries
    Replies: 4
    Last Post: 06-16-2011, 09:18 AM
  2. What is wrong with this IFF?
    By bburton in forum Reports
    Replies: 2
    Last Post: 03-16-2011, 10:42 AM
  3. Replies: 6
    Last Post: 10-12-2010, 09:35 AM
  4. What's wrong with this query?
    By jsoldi in forum Queries
    Replies: 2
    Last Post: 10-11-2010, 07:45 AM
  5. What am I doing wrong?
    By brandon in forum Access
    Replies: 2
    Last Post: 08-03-2008, 10:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums