Create Local Table

B

Bryan Hughes

Hello,

I have a table with a fe for users and be that holds just my tables

I have code that will create tables, but it creates them in the be and links
them, not in the fe where I want them to be used as temp tables and deleted
on opening and closing of the fe.

I use the fExistTable function to check if the table exists.

Then I run this sub from a class module:
Sub sClean_Local_Client()
On Error GoTo ErrorHandler
gstrSubProcName = "sClean_Local_Client()"

'Check to see if Local Client temp table exists
gblnTest = fExistTable("tblClient_Local_Temp")

'If table exists the clean information from table
If gblnTest = True Then
strSQL = "DELETE * FROM tblClient_Local_Temp;"

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Else
'if table does not exist then create it
DoCmd.CopyObject , "tblClient_Local_Temp", acTable,
"tblUSys_Client_Local"
End If

.. . .
End Sub

How can I make this table in the always be created in the users local fe and
not the be?
-TFTH
Bryan
 
A

Allen Browne

CopyObject is the problem. Use CreateTableDef() instead.
Alternatively, execute a DDL query statement such as:
dbEngine(0)(0).Execute "CREATE TABLE ...

However, it would probably be easier to just create the table in the front
end, and leave it there. Each user automatically gets the new table when you
give them the updated front end.
 
T

Tim Ferguson

I want them to be used as temp tables and deleted
on opening and closing of the fe.

Just a thought -- this is likely to cause a great deal of file bloat. I
would recommend one of:

1) Keep the temp table, but empty it before use with a

CurrentDB().Execute "DELETE FROM MyTempTable", dbFailOnError


2) Create the temp table in a temporary mdb file, which you can delete
afterwards:

' create a new empty database
Set dbTemp = ws.CreateDatabase("h:\temp\~928347.mdb", etc)

' create the new table inside it
dbTemp.Execute "CREATE TABLE MyTemp... etc", dbFailOnError


' and link it in to current Front End
Set dbFE = CurrentDB()
dbFE.tablefs.Append dbFE.CreateTableDef(acLinkedTable, etc)


and then at the end...

' unlink it
dbFE.TableDefs("NewTempTable")

' and get rid of the temp file
Kill "h:\temp\~928347.mdb"


FWIW, I think I'd go for the first one, but it's whatever suits your
needs.

B Wishes


Tim F
 
B

Bryan Hughes

Allen or Tim,

Thanks for the help. My only problem is that I need the AutoNumber field to
set back to zero before each call. This could happen up 5 to 10 times per
user session. Is there a way to do this, or is there a better solution?

-TFTH
Bryan
 
T

Tim Ferguson

My only problem is that I need the AutoNumber field to
set back to zero before each call. This could happen up 5 to 10 times
per user session. Is there a way to do this, or is there a better
solution?

Need?? or would like it to..? Remember that ANs are not reliable record
counters; just identifiers. If you _have_ to control what value an
autonumber takes, then you probably should not be using an autonumber.

It is easy enough to reset the starting seed back to zero by emptying the
table and compacting the mdb, but this obviously involves closing the file.
Does that conflict with what you call a "session"? You may have to provide
(i.e. program) a different solution.

B Wishes


Tim F
 
B

Bryan Hughes

Time,

Yes closing the mdb is not an option for this. I do have it emptying and
compacting on close.

What I am trying to do is when the user initaites a procedure for a
particular set of data, it retrives it from the main table and inserts it
into the temp table,
before inserting this data the temp table is emptied. I need to either, add
and reset a counter, or reset the autonumber to use as a temporary counter,
this is then used to fill an activex list control that I use for the user
interface.

Is there a way to do this, or is there a better way to do this?

-TFTH
Bryan
 
A

Allen Browne

If you really want to recreate the table each time, how about including an
empty copy of the table in your database, and using CopyObject?
 
B

Bryan Hughes

Allen,

In the FE or BE. I have an empty copy in the be and this is where the
problem is, when I do copyobject it creates but in the be.

Should I move thes empty tables to the fe instead?

-TFTH
Bryan
 
T

Tim Ferguson

I need to either, add
and reset a counter, or reset the autonumber to use as a temporary
counter, this is then used to fill an activex list control that I use
for the user interface.

It depends a little bit on how you are importing the data. If it's a
line-at-a-time (e.g. vba parsing a text file) then it's easy just to add
a counter of your own. If you are using an append query to get the rows,
then you might be able to mangle the SQL to create an extra column. If
all else fails then you can add the counter after the fact with something
like

UPDATE MyTable AS A
SET MyCounter = (
SELECT COUNT(*)
FROM MyTable AS B
WHERE B.SortingColumn <= A.SortingColumn
)

but I have not tested this..!

Probably the best answer, although not always possible, would be to get a
proper counter in the file you are importing because that you also give
you a path back to the original data is there should be errors in the
imported stuff.

B Wishes

Tim F
 
B

Bryan Hughes

Is this the best solution for what I am trying to do, or would running a
CREATE TABLE statement be better?

-TFTH
Bryan
 
A

Allen Browne

Doesn't matter, but copying an existing table would be much easier and
probably more efficient.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top