Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    can i rename a database from code? (Access 2000)

    i want to rename a database outside the current database i am working in. The path of the database is C:BEstoreNewDB.mdb
    The name of the database is NewDB.MDB. How can i rename it to Students.mdb, through a code from the current database?
    I have a form in this dataabse and in the OnClick event i want to rename the dtabase NewDB.mdb.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: can i rename a database from code? (Access 2000)

    Use the VB instruction Name. Its format is

    Name oldname As newname

    The arguments are strings.

    In your case

    Name "C:BEStoreNewDB.mdb" As "Students.mdb"

    If you want to move the database to another folder, you must also supply a path for newname.

    The Name instruction won't overwrite an existing file. If you want to replace an existing file, you must delete it first with the Kill instruction.

  3. #3
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: can i rename a database from code? (Access 2000)

    Hans,

    Could you please provide more info on the Kill instruction. This looks to be something I could use. What Object and Class is it?
    Regards,

    Gary
    (It's been a while!)

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: can i rename a database from code? (Access 2000)

    Gary,
    Kill is just a statement.
    Kill "C:My DocumentsMyFile.mdb"
    will delete the file MyFile.mdb in the directory c:My Documents, the same as you would delete it in explorer.
    Francois

  5. #5
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: can i rename a database from code? (Access 2000)

    As noted you can use Kill statement to delete a file or files. It is one of the older statements in VB/VBA that are still present primarily to provide backwards compatability. If you need to do a lot of file manipulation - moving, copying, creating, or deleting files & folders - determining if a file or folder exists - getting a file or folder path - etc, etc - instead of using archaic VB statements, I'd recommend using the File System Object model for file manipulation functions. This object model provides a full set of properties and methods for working with files, folders, and drives in a more sophisticated (ie, object oriented) fashion than that provided by older VB statements. It's available in VB/VBA 6.0 and later. To use the FSO set a reference in VBE to the Microsoft Scripting Runtime library (../SYSTEM32/SCRRUN.DLL). For more info see VB "Help" files (you'll have to dig around to find the FSO help files...).

    On the other hand, "Kill" works just fine if you simply want to delete a file.

    HTH

Posting Permissions

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