A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Create Local Table



 
 
Thread Tools Display Modes
  #1  
Old September 8th, 2004, 12:28 AM
Bryan Hughes
external usenet poster
 
Posts: n/a
Default Create Local Table

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


  #2  
Old September 8th, 2004, 06:48 AM
Allen Browne
external usenet poster
 
Posts: n/a
Default

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.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bryan Hughes" wrote in message
...
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



  #3  
Old September 8th, 2004, 07:18 PM
Tim Ferguson
external usenet poster
 
Posts: n/a
Default

"Bryan Hughes" wrote in news:
:

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

  #4  
Old September 9th, 2004, 06:23 PM
Bryan Hughes
external usenet poster
 
Posts: n/a
Default

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


"Bryan Hughes" wrote in message
...
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



  #5  
Old September 9th, 2004, 07:44 PM
Tim Ferguson
external usenet poster
 
Posts: n/a
Default

"Bryan Hughes" wrote in
:

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

  #6  
Old September 9th, 2004, 09:05 PM
Bryan Hughes
external usenet poster
 
Posts: n/a
Default

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


"Tim Ferguson" wrote in message
...
"Bryan Hughes" wrote in
:

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



  #7  
Old September 10th, 2004, 03:19 AM
Allen Browne
external usenet poster
 
Posts: n/a
Default

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?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Tim Ferguson" wrote in message
...
"Bryan Hughes" wrote in
:

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



  #8  
Old September 10th, 2004, 06:45 PM
Bryan Hughes
external usenet poster
 
Posts: n/a
Default

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

"Allen Browne" wrote in message
...
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?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Tim Ferguson" wrote in message
...
"Bryan Hughes" wrote in
:

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





  #9  
Old September 10th, 2004, 07:16 PM
Tim Ferguson
external usenet poster
 
Posts: n/a
Default

"Bryan Hughes" wrote in
:

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

  #10  
Old September 10th, 2004, 07:26 PM
Allen Browne
external usenet poster
 
Posts: n/a
Default

"Bryan Hughes" asked:
Should I move thes empty tables to the fe instead?


yes.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Autonumber Ally H. General Discussion 7 August 27th, 2004 04:51 PM
Complicated Databse w/many relationships Søren Database Design 7 July 13th, 2004 05:41 AM
Create Table Statement nagesh Running & Setting Up Queries 1 June 4th, 2004 04:12 PM
How to extract data from multiple Access databases to create a Pivot table Android Worksheet Functions 4 February 6th, 2004 04:22 PM


All times are GMT +1. The time now is 01:36 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.