Access: how to rename a table using a macro?

Solved
angy21 Posted messages 39 Status Member -  
 tilalilalu -
Hello,

I have a problem with Access. After a lot of searching, I have only resolved it halfway.

Indeed, through a macro, I import an Excel file that I convert into an Access table.

Then, still through a macro, I duplicate this table.

And then comes the rest of my problem because I need to rename (still via macro) this second table but with a random name (name entered manually).

Is there a solution to my problem? Thank you in advance for your help.

--
Angy who wants to add more arrows to her quiver
Every problem has 1 solution, but the hardest part is finding it!
Configuration: Access 2000

3 answers

  1. random Posted messages 1612 Status Member 155
     
    ```html you need a function or a procedure vba
    Sub nom(ex As String)
    Dim u As DAO.Database
    Set u = CurrentDb
    u.TableDefs(ex).Name = InputBox("enter the new name for " & ex)
    End Sub
    you can replace function with sub

    and ask your macro to execute this code
    don't forget to add dao to the vba references

    --
    isn't life beautiful? ```
    2
    1. angy21 Posted messages 39 Status Member 1
       
      Thank you for your reply. I'll give it a try, but as I told Nabil, I'm struggling with VBA... However, I will try to manage. I'll be sure to keep you updated.

      --
      Angy who wants to add more arrows to her quiver
      Every problem has one solution, but the hardest part is finding it!
      0
    2. angy21 Posted messages 39 Status Member 1
       
      Hello Random,

      I’m reaching out to you again because, as I feared, I haven’t been able to follow your VBA advice.

      Can I ask for your help and request more details on how I should proceed? I'm more than a beginner in VBA.

      Thank you in advance, and see you soon.

      --
      Angy who wants to add more arrows to her quiver
      Every problem has a solution, but the hardest part is finding it!
      0
    3. angy21 Posted messages 39 Status Member 1
       
      Hello Random,

      I still haven't found the solution to my problem, but you've inspired me to start with VBA. Since Friday, I've been getting into programming thanks to a book.

      I think this can only help me with future problems to solve. Thanks again

      --
      Angy who wants to add more arrows to her quiver
      Every problem has one solution, but the hardest part is finding it!
      0
    4. angy21 Posted messages 39 Status Member 1
       
      I've found the solution... After a lot of searching, I finally found it with an Access macro

      All you need to do is use the BEnter function!!!

      Thanks anyway for your help.

      --
      Angy who wants to add more arrows to her quiver
      Every problem has one solution, but the hardest part is finding it!
      0
    5. tilalilalu
       
      Hello,

      Could I know how you use this famous BEntrée function?
      0
  2. angy21 Posted messages 39 Status Member 1
     
    Hello,

    Can anyone help me, please? I'm stuck...

    Thanks again

    --
    Angy who wants to add more arrows to her quiver
    Every problem has one solution, but the hardest part is finding it!
    0
  3. nabil
     
    Hi,

    If you really want to work with macros this time, I believe you will have to use VBA because I don’t think there’s a way to modify table definitions. But what you can do is create a function in VBA that will create your second table and automatically rename it. After that, you can call this function via a macro if you absolutely must use a macro. For that, you will need to manipulate the TableDef object; check the help documentation or look it up online.

    Hope this helps!
    0
    1. angy21 Posted messages 39 Status Member 1
       
      Thank you first of all for your response, and no, I don't have to use macros, but to be honest, I'm struggling with VBA... so it's easier for me to stick with Access macros.

      See you soon

      --
      Angy who wants to add more arrows to her quiver
      Every problem has one solution, but the hardest part is finding it!
      0