Results 1 to 6 of 6

Thread: Syntax Error

  1. #1
    2 Star Lounger
    Join Date
    Jan 2003
    Location
    Toledo, Ohio, USA
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Syntax Error

    This should be relatively simple. Can someone enlighten me as to the correct syntax for the following statement? Thanks in advance.

    Function CompactEvents()
    ' Compact the EventsManagement1.mdb in C:EmjayEvents

    DoCmd.RunCommand acCmdCompactDatabase "C:EmjayEventEvent management1.mdb"

    End Function

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Syntax Error

    What is the error message you receive?
    Notice that you cannot compact a database from itself.
    If you want to compact a database you have te define a new mdb and compact the database from that new mdb.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2003
    Location
    Toledo, Ohio, USA
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Syntax Error

    The error message simply states: 'Compile error' and then on the following line of the message box it simply says 'syntax error'. It doesn't give any clues.

    Also, I am trying to run this statement from a different .mdb.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Syntax Error

    I don't know of any RunCommand constants that take an argument, so that may be the syntax error in question. Try using the CompactDatabase method instead. You didn't indicate which version of Access you're using, so I'll show you the DAO version.

    <pre>DBEngine.CompactDatabase "Northwind.mdb", "Nwind.mdb"</pre>


    If you're using Access 2000, bring up help in the VBE and type "compact database" (without the quotes) in the answer wizard tab and you'll get both methods.
    Charlotte

  5. #5
    2 Star Lounger
    Join Date
    Jan 2003
    Location
    Toledo, Ohio, USA
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Syntax Error

    I'm using Access97 with WIN98se. Also I see that this requires renaming the objects. Is there an easy way to get the compacted object (.mdb) renamed back to its original value?

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Syntax Error

    The simplest way to handle it is to compact to a new temporary name. If you don't get any errors on the compact, you can store the original filename to a string variable, delete the old file and then rename the new one to the original name. Even Access does it this way, so there's no shame in following precedent. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    You will need to create the temporary name as a string as well and test to see if it exists before you try to compact to it. If it exists, kill it first and then compact to that filename.
    Charlotte

Posting Permissions

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