|
-
Aug 21st, 2005, 10:14 PM
#1
Thread Starter
Member
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. 
-
Aug 21st, 2005, 11:08 PM
#2
Re: check if a table is open
 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:
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
For Each obj In dbs.AllTables
If obj.Name = "Mailboxes" And obj.IsLoaded Then DoCmd.Close acTable, obj.Name
Next obj
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 22nd, 2005, 12:21 AM
#3
Thread Starter
Member
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. 
-
Aug 22nd, 2005, 12:39 PM
#4
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
-
Aug 22nd, 2005, 09:22 PM
#5
Thread Starter
Member
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. 
-
Aug 23rd, 2005, 03:18 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|