Results 1 to 4 of 4
  1. #1
    fcarvalho is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Sep 2018
    Posts
    2

    Error in SQL


    Good afternoon. I have an sql instruction like that:

    ...IN 'CurrentProject.Path & " \ historicoapolice.mdb '" & _ But it gives me error

    But if i put like this:

    ....IN ' C:\loja seguros\ historicoapolice.mdb '" & _ it does not matter anymore.

    What i'm doing wrong? Can someone help me? Thank you

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Link the external data as a table .
    the. Run the query.

  3. #3
    fcarvalho is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Sep 2018
    Posts
    2
    Hello. Thank you for the feedback. The "historicoapolice.mdb" is a database to store customer history. In the main MDB there is a button. Clicking executes the sql statement and sends the selected tab to history. It is not connected to the main. I would like the sql statement to run anywhere where the mdb was installed, since the folder is the same.
    So, rather than ....IN ' C:\loja seguros\ historicoapolice.mdb '" & _, i would like this......IN 'CurrentProject.Path & " \ historicoapolice.mdb '" & _ But it gives me error. Mujst doing something wrong, but why?

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You MUST concatenate the path, just as you have the db name.

    ...IN '" & CurrentProject.Path & "\historicoapolice.mdb '" & _
    (Edit: just noticed you have a space before and after the slash. I removed it)


    I never liked using the line continuation option. It makes it too hard to read.
    So I use
    Code:
        sSQL = "SELECT tblClients.Clients_PK, tblClients.LastName & ', ' & tblClients.FirstName As FullName"
        sSQL = sSQL & " FROM tblClients"
        sSQL = sSQL & " INNER JOIN tblJunction ON tblClients.Clients_PK = tblJunction.Clients_FK"
        sSQL = sSQL & " WHERE tblJunction.Visits_FK = " & Me.cboVisits
        sSQL = sSQL & " ORDER BY LastName;"
        Debug.Print sSQL
        Set r = CurrentDb.OpenRecordset(sSQL)
    Notice the spaces are at the beginning of the line, not at the end. Very easy to see if there are missing spaces.


    If you set a break on the line after the debug line, it is easy to see if the SQL is correctly formed.
    You can also copy the SQL in the immediate window, create a new query, switch to SQL View and paste in the SQL.
    Then you can try to execute the query..... Access will tell you if there are errors in the SQL.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-22-2016, 05:05 AM
  2. Replies: 1
    Last Post: 07-26-2016, 06:34 AM
  3. Replies: 6
    Last Post: 03-17-2016, 02:10 PM
  4. Replies: 3
    Last Post: 01-23-2014, 07:49 AM
  5. Replies: 0
    Last Post: 07-16-2012, 05:42 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