Results 1 to 3 of 3
  1. #1
    Join Date
    May 2003
    Location
    Costa Rica
    Posts
    40

    Unhappy Unanswered: Delete a relation or delete a table with a relation

    I made a program. It has no records right now. I made a relation between inform1 to inform2. I want to delete the relation using a Visual Basic command, a macro or a SQL statement. When I do it manually, Access sends me the following message. You are trying to delete a table that has a relation. Do you want access to delete the relation?. I just say yes, and everything is Ok. The problem is that I need not to do it manually, to do it using a command, macro or something else. When I do it in a macro or in a module (using visual basic), it doesnīt permit me to delete the table. It says that the table has a relation, and that I canīt delete the table because of the relation. I had read a lot about Create.Relation command, Delete (method), and everything, but I havenīt found how to delete the relation, or at least, that the program could send me the same msgbox that sends me when I do it manually (you are trying to delete a table that has a relation. Do you want access to delete the relation?) in order to just touch yes and solution made. I had tried with SetWarnings, and everything. I know there is a way to delete all the relations, but that means that after that I will have to Create all the other relations. Could anyone help me. It is urgent!!!!. Thank you

  2. #2
    Join Date
    Sep 2002
    Location
    Land of OZ
    Posts
    173

    Re: Delete a relation or delete a table with a relation

    Originally posted by Manuel Gimenez
    I made a program. It has no records right now. I made a relation between inform1 to inform2. I want to delete the relation using a Visual Basic command, a macro or a SQL statement. When I do it manually, Access sends me the following message. You are trying to delete a table that has a relation. Do you want access to delete the relation?. I just say yes, and everything is Ok. The problem is that I need not to do it manually, to do it using a command, macro or something else. When I do it in a macro or in a module (using visual basic), it doesnīt permit me to delete the table. It says that the table has a relation, and that I canīt delete the table because of the relation. I had read a lot about Create.Relation command, Delete (method), and everything, but I havenīt found how to delete the relation, or at least, that the program could send me the same msgbox that sends me when I do it manually (you are trying to delete a table that has a relation. Do you want access to delete the relation?) in order to just touch yes and solution made. I had tried with SetWarnings, and everything. I know there is a way to delete all the relations, but that means that after that I will have to Create all the other relations. Could anyone help me. It is urgent!!!!. Thank you

    Hi Manuel

    Assuming that you have a relationship from inform1 (Primary Key) to inform2 (Foreign Key) use the following to delete relationship then inform2 table. The name of the relationship is defaulted to "inform1inform2"

    Dim db As DAO.Database

    Set db = CurrentDb()
    db.Relations.Delete ("inform1inform2")
    db.TableDefs.Delete "inform2"

    Hope that this works.
    Cheers
    Mona
    ________________________________
    Life is too short to be sane or sensible. Weird people rule and normal people suck

  3. #3
    Join Date
    May 2003
    Location
    Costa Rica
    Posts
    40

    Smile Thanks to Mona

    I would really like to give thanks to the Moderator called Mona. He/She really knows too much about Access and in a simple 4 lines he/she gave me the answer of a lot of months that I had spend reading and trying. I just donīt know if this is the correct way to give thanks. If it is not, Iīm sorry. Please give all the point I reserve for the question to Mona. Thank you very much. This forum is really usefull considering that it has people like Mona.

Posting Permissions

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