Results 1 to 6 of 6

Thread: check if a table is open

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Exclamation check if a table is open

    Hi,


    I have to close a table manually in vba. I am usign the following command

    DoCmd.Close acTable, "Mailboxes", acSaveYes

    Now this works fine, but sometimes it gives an error such that my whole Access Database hangs and I have to close it via the task manager and cannot debug. But I suspect the problem is possible if the mailboxes table is not open in the first place, and I run the above command. So I want to check if a table is open and if yes I want to run the above command. Does anyone know of such a command. I couldn't find it all over msdn

    Something like


    if Mailboxes table open then

    DoCmd.Close acTable, "Mailboxes", acSaveYes

    end if



    Thanks
    When you know you can do it, there is no power on earth that can stop you.

  2. #2
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: check if a table is open

    Quote Originally Posted by rochak
    I have to close a table manually in vba.
    Are you opening the table in vba??..

    You can use the AllTables Collection to determine if the table is loaded and close it if it is..

    VB Code:
    1. Dim obj As AccessObject, dbs As Object
    2.   Set dbs = Application.CurrentData
    3.   For Each obj In dbs.AllTables
    4.     If obj.Name = "Mailboxes" And obj.IsLoaded Then DoCmd.Close acTable, obj.Name
    5.   Next obj
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Re: check if a table is open

    Danny, thanks I just understood why my stuff was hanging. If I open the mailboxes table without vba, then your code works just fine. However, if I open the table using vba, it is then that my access project hangs. Can you please help me in this?
    When you know you can do it, there is no power on earth that can stop you.

  4. #4
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: check if a table is open

    Rochak.

    You will need to ensure that any references that you have set to things like, fields, or the table itself are cleared before closing the table..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2005
    Location
    NTU, Singapore
    Posts
    42

    Re: check if a table is open

    Danny, I am using a switchboard which has two buttons. One button opens up the form which edits the records on the Mailboxes table. I am not doing this using any recordsets so that references problem is minimized. The second button runs a macro which displays the mailboxes table. If by any chance the first form remains open (user hasnot exit it) and at the same time he clicks on the macro button, the stuff simply hangs. Is there a way for the macro to work in conjunctions with the edit form. Thanks
    When you know you can do it, there is no power on earth that can stop you.

  6. #6
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: check if a table is open

    Without taking a look at the Macro I will be stabbing in the dark, but my stab is that you can close the form and then open the table, however due to being unable to control the table closure you would be better off setting a form as datasheet view to display the table instead..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

Posting Permissions

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



Click Here to Expand Forum to Full Width