Close

Results 1 to 5 of 5
  1. #1
    DF MaSter daven's Avatar
    Join Date
    Feb 2004
    Location
    Devon
    Posts
    83
    Thanks
    5
    Thanked:        5
    Karma Level
    250

    Default DoCmd.RunSQL In Access DB

    Hi Guys,

    Having problems trying to run a SQL Script in VB. The SQL works fine in a query but in VB I get "Syntax error" (you can write what I know about VB on the back of a box of matches ). I want the code to run as a function so I can call it from a macro rather than a query so have tried the following:-

    Function DoSQL()
    Dim SQL As String

    SQL = "INSERT INTO AssetDB (FAR_AssetCode)" & _
    "SELECT NewAssetData.FAR_AssetCode" & _
    "FROM NewAssetData" & _
    "WHERE NewAssetData.FAR_AssetCode > (Select Max(FAR_AssetCode) from AssetDB);"

    DoCmd.RunSQL SQL

    End Function

    Any help appreciated

    Dave

  2. #2
    DF VIP Member /dev/null's Avatar
    Join Date
    Feb 2004
    Location
    Behind You
    Posts
    2,952
    Thanks
    0
    Thanked:        0
    Karma Level
    451

    Default Re: DoCmd.RunSQL In Access DB

    Try removing the semi-colon from the end of your query - I may be wrong, but I have a feeling VB doesn't require it.

    John.

  3. #3
    DF MaSter daven's Avatar
    Join Date
    Feb 2004
    Location
    Devon
    Posts
    83
    Thanks
    5
    Thanked:        5
    Karma Level
    250

    Default Re: DoCmd.RunSQL In Access DB

    Quote Originally Posted by John Keymer View Post
    Try removing the semi-colon from the end of your query - I may be wrong, but I have a feeling VB doesn't require it.

    John.
    Thanks John - had tried that but it make no difference! Have deleted it now anyway!

    Dave

  4. #4
    DF VIP Member SiE's Avatar
    Join Date
    Jan 2001
    Location
    My comfy sofa
    Posts
    7,211
    Thanks
    196
    Thanked:        407
    Karma Level
    787

    Default Re: DoCmd.RunSQL In Access DB

    you needed to put spaces before the " on each line I think on the SQL statement

  5. #5
    DF MaSter daven's Avatar
    Join Date
    Feb 2004
    Location
    Devon
    Posts
    83
    Thanks
    5
    Thanked:        5
    Karma Level
    250

    Default Re: DoCmd.RunSQL In Access DB

    Quote Originally Posted by SiE View Post
    you needed to put spaces before the " on each line I think on the SQL statement
    SiE - you star! Karma coming your way! Knew it would be something simple!

    Cheers

    Dave

Similar Threads

  1. BTBroadband access barred?!
    By ski in forum Internet Connections & VPNs
    Replies: 1
    Last Post: 28th November 2002, 12:26 PM
  2. need access but don`t know password
    By yorg in forum PC Problems
    Replies: 4
    Last Post: 11th October 2002, 06:59 PM
  3. access problem
    By Aware in forum Forum Bug & Error Reports
    Replies: 1
    Last Post: 30th September 2002, 09:24 PM
  4. Free to access channels
    By benjiguy in forum Digital Satellite TV
    Replies: 4
    Last Post: 23rd September 2002, 09:56 PM

Social Networking Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •