|
Question : checking if a table exists
|
|
I make a table (dynamic) Do stuff with it Then delete the table.
But...
In a multi - user enviroment, it has to be like this.
See if the table exists, yes ? wait till deteted Make the table
no? Make the table.
How do i check if tha table exists?
Thanks in advance, Justus
|
|
Answer : checking if a table exists
|
|
Dedushka: Thank you for trying to cover me, but I had made another mistake too :-)
Here is a version of the function that works:
Function DoesTableExist(pTableName)
Dim MyDB As Database Dim MyTable As TableDef
Set MyDB = CurrentDb For Each MyTable In MyDB.TableDefs If MyTable.Name = pTableName Then ' Msgbox ("Found it!") DoesTableExist = True Exit For End If Next
Set MyTable = Nothing MyDB.Close Set MyDB = Nothing
End Function
To wait for the table to be deleted:
While DoesTableExist("Table Name") = True DoEvents Wend
If this is a setting where you need to wait because you don't want to destroy other users currently running code or report etc. then use the above. If you are just making a temp table for some purpose then consider this;
What I normally do in an multi-user environment is to not run a make-table query if the table already exist. Something like this is better (in my opinion):
' English code syntax ;-)
If table does not already exist then Make table, remember to include a Login field that states which user who owns the records (Note 1) Else Delete all records marked with current users login, these are leftovers from last run Append query to put in the new records, along with current users login. End If
Rest of code
A good idea is to let the form, report or code that uses that newly added information "clean up" by deleting the records marked with my login, but the next run will also take care of this.
Note 1) If you are in a front end/back end environment, and are not comfortable with creating tables in the other database/server, then you should make sure that the table is already there and then skip the make table steps in the above setting.
|
|
|
|