You have given me information w/o answering my question. i guess i should
give mroe background though.
when the user opens the DB, a start form is run, that archives old data,
then the user goes about his/her business. the startform archiving is my
problem.
each archived table has to be in a seperate table. so i must make this
table when the archiving is started. I can't go into the archive DB and
create tables every day and whatnot. that's why i liked the maketable
command. sure it may be inefficent, but working with small data in a time
insensitive process means i can be lax on runtimes. this is why i would like
to open a second database with vba so i can create the table needed to fill
the archive data.
i tried your method of doing the make query, but i need to create the table
in the archive first. access won't make a table that isn't there.
here is the code i use now to create the table in the current database, but
as i said, i'd like to create the table in the archive database
Private Sub Form_Load()
Dim dbsC1408 As Database
Dim rstCoil As Recordset
Dim strSQL As String
Dim crtTbl As String
'Dim dbsArchive As Database
Set dbsC1408 = CurrentDb
Set rstCoil = dbsC1408.OpenRecordset("tblCoils")
rstCoil.MoveFirst
Do Until rstCoil.EOF
If rstCoil!Date < (Date - 30) Then
'Make table statmenet here
crtTbl = "CREATE TABLE " + rstCoil!CoilID
crtTbl = crtTbl + "bak (Ref SINGLE, Front SINGLE, Back SINGLE, Power
CHAR(50), CapBanksFw CHAR(50), PresetHex CHAR(50), CapBanksHex CHAR(50), Ia
SINGLE, Va SINGLE, Kw SINGLE, [Time] LONG);"
dbsC1408.Execute (crtTbl)
'select query
strSQL = "INSERT INTO " + rstCoil!CoilID + "bak"
strSQL = strSQL + " ( Ref, Front, Back, Power, CapBanksFw, PresetHex,
CapBanksHex, Ia, Va, Kw, [Time]) SELECT ["
strSQL = strSQL + rstCoil!CoilID
strSQL = strSQL + "].Ref, ["
strSQL = strSQL + rstCoil!CoilID
strSQL = strSQL + "].Front, ["
strSQL = strSQL + rstCoil!CoilID
strSQL = strSQL + "].Back, ["
strSQL = strSQL + rstCoil!CoilID
strSQL = strSQL + "].Power, ["
strSQL = strSQL + rstCoil!CoilID
strSQL = strSQL + "].CapBanksFw, ["
strSQL = strSQL + rstCoil!CoilID
strSQL = strSQL + "].PresetHex, ["
strSQL = strSQL + rstCoil!CoilID
strSQL = strSQL + "].CapBanksHex, ["
strSQL = strSQL + rstCoil!CoilID
strSQL = strSQL + "].Ia, ["
strSQL = strSQL + rstCoil!CoilID
strSQL = strSQL + "].Va, ["
strSQL = strSQL + rstCoil!CoilID
strSQL = strSQL + "].Kw, ["
strSQL = strSQL + rstCoil!CoilID
strSQL = strSQL + "].Time FROM "
strSQL = strSQL + rstCoil!CoilID + ";"
'Make the backup table
dbsC1408.Execute (strSQL)
'delete table command
dbsC1408.TableDefs.Delete (rsCoil!CoilID)
'delete record
rstCoil.Delete
End If
rstCoil.MoveNext
Loop
rstCoil.Close
DoCmd.OpenForm "frmCoils"
DoCmd.Close acForm, "frmStart"
End Sub
so after the Set dbsC1408 = CurrentDb i'd like to have a statement
Set dbsArchive = 'way to open database from a different location'
and then adjust the statments to use dbsArchive instead of dbsC1408
i hope this gives you a better understanding of what i'm looking for
Klatuu said:
I always avoid using make table queries. They are very inefficient. Since
they don't know the data structure of the original table, they use defaults.
Text fields are alway created with a length of 255 or whatever is set in the
options for example.
The method I suggested is about as easy as it gets. If you follow my
example, it will be a lot less code. You use an append query to copy the
data from production to archive. If you need to start with an empty table,
create a delete query that points to the archve database. It can all be done
from your production front end.
:
My plan was to have a second archive DB where the old data was stored. i was
just seeing if i could get the process to work on a single db. I got the VBA
code to work in the database. My next goal is to get this to work with a
second db.
My question now is, how would i use VBA to open a DB in another location,
more specificaly on a seperate computer/server. (the application isn't
really server/sql major stuff. just data being thrown from one db to another)
would it be like
Dim dbsArchive as Database
Set dbsArchive = "\\Servername\Directory\Subdirector\dbname"
::create sql statments to create new table::
dbsArchive.Execute (sql statement)
::make sql statment to make insert into table::
dbsArchive.Execute (sql statment)
???
so if my archive DB was located on the server named SmoothDB in the director
named RollingData, and the name of the database was rollarch.mdb
my sql statment would be
Set dbsArchive = "\\SmoothDB\RollingData\rollarch.mdb"
??