473,609 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programatically Populate New Database With Tables

Using code in MyDateBase I create a new database named MyNewDatabase. Now I
need to import (or export) using code in MyDatabase tables in another
external database named MyData to MyNewDatabase. Is there a way to do it?
What is the code?

Thanks,

Steve
Nov 13 '05 #1
3 2208
I work from a table created mainly from the documenter. The table and fields
are
ztblTempStructu re
TableName
FieldName
FieldType
FieldSize
Indexed
PrimaryKey

And the code is:

Function BldTempTables() As Boolean
'============== =============== =============== =============== =
' Programmer: Duane Hookom
' Revision #:
' Called From:
' Date: 7/5/01
' Parameters:
'============== =============== =============== =============== =
On Error GoTo BldTempTables_E rr
Dim strErrMsg As String 'For Error Handling

'Dim the objects
Dim dbThis As DAO.Database
Dim dbTemp As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim ndx As DAO.Index
Dim rsStruct As DAO.Recordset 'the struct table

'Dim the variables
Dim strFolder As String 'the folder this application is located
in
Dim strThisDBName As String 'the name of this MDB
Dim strTempDBName As String 'The name of the temp mdb
Dim strTableName As String 'the table name

Set dbThis = CurrentDb
strThisDBName = dbThis.Name
strFolder = Left(strThisDBN ame, Len(strThisDBNa me) -
Len(Dir(strThis DBName)))
strTempDBName = strFolder & "PrdRptTemp.MDB "
On Error Resume Next
Kill strTempDBName 'if the old one exists, delete it
On Error GoTo BldTempTables_E rr
'Create the new empty database
Set dbTemp = CreateDatabase( strTempDBName, dbLangGeneral)
Set rsStruct = dbThis.OpenReco rdset("Select TableName, FieldName,
FieldType, FieldSize, Indexed " & _
"FROM ztblTempStructu re ORDER BY TableName")
With rsStruct
If Not .EOF Then
.MoveFirst
Do Until .EOF
strTableName = !TableName
Set tdf = dbTemp.CreateTa bleDef(strTable Name)
Do Until !TableName <> strTableName
Select Case !FieldType
Case dbText
Set fld = tdf.CreateField (!FieldName,
!FieldType, !FieldSize)
fld.AllowZeroLe ngth = True
Case Else
Set fld = tdf.CreateField (!FieldName,
!FieldType)
End Select

tdf.Fields.Appe nd fld
tdf.Fields.Refr esh
.MoveNext
If .EOF Then
Exit Do
End If
Loop
dbTemp.TableDef s.Append tdf
dbTemp.TableDef s.Refresh

Loop
End If
.Close
End With

'Create the indexes
Set rsStruct = dbThis.OpenReco rdset("Select TableName, FieldName,
FieldType, Indexed, PrimaryKey " & _
"FROM ztblTempStructu re WHERE Indexed = -1 OR PrimaryKey = -1
ORDER BY TableName")
With rsStruct
.MoveFirst
If Not .EOF Then
.MoveFirst
Do Until .EOF
Set tdf = dbTemp.TableDef s(!TableName)
'Debug.Print tdf.Name
strTableName = !TableName
Do Until !TableName <> strTableName
'Debug.Print "-" & !FieldName
Set ndx = tdf.CreateIndex (!FieldName)
Set fld = ndx.CreateField (!FieldName, !FieldType)
ndx.Fields.Appe nd fld
'set up the primary key field.
If !PrimaryKey = True Then
ndx.Primary = True
End If
tdf.Indexes.App end ndx
tdf.Indexes.Ref resh
.MoveNext
If .EOF Then
Exit Do
End If
Loop
Loop
End If
.Close
End With
Set rsStruct = dbThis.OpenReco rdset("Select Distinct TableName From
ztblTempStructu re")
'relink the tables
With rsStruct
.MoveFirst
Do Until .EOF
DoCmd.DeleteObj ect acTable, !TableName
DoCmd.TransferD atabase acLink, "Microsoft Access",
strTempDBName, acTable, !TableName, !TableName
dbThis.TableDef s.Refresh
.MoveNext
Loop
.Close
End With
Set rsStruct = Nothing
Set dbThis = Nothing
Set dbTemp = Nothing
BldTempTables = True

BldTempTables_E xit:
Exit Function

BldTempTables_E rr:
Select Case Err
Case Else
strErrMsg = strErrMsg & "Error #: " & Format$(Err.Num ber) &
vbCrLf
strErrMsg = strErrMsg & "Error Description: " & Err.Description
MsgBox strErrMsg, vbInformation, "BldTempTab les"
BldTempTables = False
Resume BldTempTables_E xit
End Select
End Function
--
Duane Hookom
MS Access MVP
"PC Datasheet" <no****@nospam. spam> wrote in message
news:_O******** *********@newsr ead1.news.atl.e arthlink.net...
Using code in MyDateBase I create a new database named MyNewDatabase. Now
I need to import (or export) using code in MyDatabase tables in another
external database named MyData to MyNewDatabase. Is there a way to do it?
What is the code?

Thanks,

Steve

Nov 13 '05 #2
Duane,

Thanks for your response!

I'm hoping to find code using TransferDatabas e that can be run from
MyDateBase to import tables from MyData into MyNewDatabase.

Steve
"Duane Hookom" <duanehookom@NO _SPAMhotmail.co m> wrote in message
news:eJ******** ******@TK2MSFTN GP14.phx.gbl...
I work from a table created mainly from the documenter. The table and
fields are
ztblTempStructu re
TableName
FieldName
FieldType
FieldSize
Indexed
PrimaryKey

And the code is:

Function BldTempTables() As Boolean
'============== =============== =============== =============== =
' Programmer: Duane Hookom
' Revision #:
' Called From:
' Date: 7/5/01
' Parameters:
'============== =============== =============== =============== =
On Error GoTo BldTempTables_E rr
Dim strErrMsg As String 'For Error Handling

'Dim the objects
Dim dbThis As DAO.Database
Dim dbTemp As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim ndx As DAO.Index
Dim rsStruct As DAO.Recordset 'the struct table

'Dim the variables
Dim strFolder As String 'the folder this application is located
in
Dim strThisDBName As String 'the name of this MDB
Dim strTempDBName As String 'The name of the temp mdb
Dim strTableName As String 'the table name

Set dbThis = CurrentDb
strThisDBName = dbThis.Name
strFolder = Left(strThisDBN ame, Len(strThisDBNa me) -
Len(Dir(strThis DBName)))
strTempDBName = strFolder & "PrdRptTemp.MDB "
On Error Resume Next
Kill strTempDBName 'if the old one exists, delete it
On Error GoTo BldTempTables_E rr
'Create the new empty database
Set dbTemp = CreateDatabase( strTempDBName, dbLangGeneral)
Set rsStruct = dbThis.OpenReco rdset("Select TableName, FieldName,
FieldType, FieldSize, Indexed " & _
"FROM ztblTempStructu re ORDER BY TableName")
With rsStruct
If Not .EOF Then
.MoveFirst
Do Until .EOF
strTableName = !TableName
Set tdf = dbTemp.CreateTa bleDef(strTable Name)
Do Until !TableName <> strTableName
Select Case !FieldType
Case dbText
Set fld = tdf.CreateField (!FieldName,
!FieldType, !FieldSize)
fld.AllowZeroLe ngth = True
Case Else
Set fld = tdf.CreateField (!FieldName,
!FieldType)
End Select

tdf.Fields.Appe nd fld
tdf.Fields.Refr esh
.MoveNext
If .EOF Then
Exit Do
End If
Loop
dbTemp.TableDef s.Append tdf
dbTemp.TableDef s.Refresh

Loop
End If
.Close
End With

'Create the indexes
Set rsStruct = dbThis.OpenReco rdset("Select TableName, FieldName,
FieldType, Indexed, PrimaryKey " & _
"FROM ztblTempStructu re WHERE Indexed = -1 OR PrimaryKey = -1
ORDER BY TableName")
With rsStruct
.MoveFirst
If Not .EOF Then
.MoveFirst
Do Until .EOF
Set tdf = dbTemp.TableDef s(!TableName)
'Debug.Print tdf.Name
strTableName = !TableName
Do Until !TableName <> strTableName
'Debug.Print "-" & !FieldName
Set ndx = tdf.CreateIndex (!FieldName)
Set fld = ndx.CreateField (!FieldName, !FieldType)
ndx.Fields.Appe nd fld
'set up the primary key field.
If !PrimaryKey = True Then
ndx.Primary = True
End If
tdf.Indexes.App end ndx
tdf.Indexes.Ref resh
.MoveNext
If .EOF Then
Exit Do
End If
Loop
Loop
End If
.Close
End With
Set rsStruct = dbThis.OpenReco rdset("Select Distinct TableName From
ztblTempStructu re")
'relink the tables
With rsStruct
.MoveFirst
Do Until .EOF
DoCmd.DeleteObj ect acTable, !TableName
DoCmd.TransferD atabase acLink, "Microsoft Access",
strTempDBName, acTable, !TableName, !TableName
dbThis.TableDef s.Refresh
.MoveNext
Loop
.Close
End With
Set rsStruct = Nothing
Set dbThis = Nothing
Set dbTemp = Nothing
BldTempTables = True

BldTempTables_E xit:
Exit Function

BldTempTables_E rr:
Select Case Err
Case Else
strErrMsg = strErrMsg & "Error #: " & Format$(Err.Num ber) &
vbCrLf
strErrMsg = strErrMsg & "Error Description: " & Err.Description
MsgBox strErrMsg, vbInformation, "BldTempTab les"
BldTempTables = False
Resume BldTempTables_E xit
End Select
End Function
--
Duane Hookom
MS Access MVP
"PC Datasheet" <no****@nospam. spam> wrote in message
news:_O******** *********@newsr ead1.news.atl.e arthlink.net...
Using code in MyDateBase I create a new database named MyNewDatabase. Now
I need to import (or export) using code in MyDatabase tables in another
external database named MyData to MyNewDatabase. Is there a way to do it?
What is the code?

Thanks,

Steve


Nov 13 '05 #3
rkc
PC Datasheet wrote:
Duane,

Thanks for your response!

I'm hoping to find code using TransferDatabas e that can be run from
MyDateBase to import tables from MyData into MyNewDatabase.


If you take a minute to read the helpfile on TransferDatabas e
you will find that:

<quote>
You can use the TransferDatabas e action to import or export data between
the current Microsoft Access database (.mdb) or Microsoft Access project
(.adp) and another database.
</quote>

So if you want to use TransferDatabas e to move a table from one .mdb
file to another .mdb file, neither of which are the current database,
you will need to do it in two steps using the current database as a
middle man.

It shouldn't be too difficult to actually write that little bit of code
yourself.


Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1660
by: CoreyMas | last post by:
Hello Everyone, I have been successful in creating a template column programatically using the examples provided in VS 2003. However I have not been able to programatically set the width of a template column programatically Here is the code that I have used so far
3
6303
by: Damian | last post by:
Hi. Is there a way to programatically populate a continuous form? I have an array of descriptions that I want to display in the continuous form and I have a textbox on the form called 'txtDescription' I can populate the text box using this code: Me.txtDescription.Value = myArray(1) Trouble is, I can't figure out how to get more than 1 row to display
3
11813
by: Tym | last post by:
OK - daft question of the day time... If I have database A which contains all the live data, and Database B which contains linked tables to those is A (i.e. a front end) is there a way of seeing if any tables have been addedd to A and if so, programatically creating a linked table to the new tables? Failing this, can I programatically delete all linked tables, then link re-link to every table which appears in tableA?
8
5650
by: Lumpierbritches | last post by:
Thank you in advance for any and all assistance, it is GREATLY appreciated. I was wondering if there is a way, with code to create a query for every table? Or can you use a naming convention in tables and use a wildcard to create a query for any table meeting that criteria? I have over 100 tables and when I do updates, I've been having to create append queries so that my clients don't loose data, but I would like to be able to have code...
3
2687
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to populate multiple webpages containing customer information. There isn't a one-to-one correlation between the stored procedure and a webpage. In other words, a webpage may have to refer to 1 or more DataTables to populate itself. Therefore, a...
3
2084
by: crjunk | last post by:
I have 4 different databases that I'm having to pull data from in order to populate a datagrid. I am able to do this, but my problem is that because I'm pulling the data from 4 different databases, the data is ordered alphabetically but is grouped by database. Here is an example of what is happening to the data in the datgrid with the code that I have now. DB1 Apple DB1 Bird DB1 Cake
5
5897
by: Rich | last post by:
Hello, I have a search application to search data in tables in a database (3 sql server tables). I populate 2 comboboxes with with data from each table. One combobox will contain unique CompanyID's. The second combobox will contain unique memberID's. Each of the tables that I have to search contain a CompanyID and a memberID field, and these fields are not unique in the respective tables. Like CompanyID, MemberID
5
1974
by: Ron | last post by:
Hi All, Development stage of setting up a new solution here. I CONSTANTLY have to unhook the relationships I've built via the Relationships tab on Tools, then change the Required element of a few controls on a table from yes to no, make some other adjustments to the attributes of various controls, then copy just the structure (so that the primary key resets to 1) to another name, delete the first table, rename the new table to what it...
12
1494
by: Andy B | last post by:
I need to custom build and use a dataset in c# to use with xml. Does anybody know where I can find out how to do something like this? I was going to create a class that generated the dataset and its data to hide all of the complex (or should I say the huge chuncks of code) from the page itself.
0
8573
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8541
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7002
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4021
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.