Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Transfer Database Please!!! 1

Status
Not open for further replies.

air1jcw

Technical User
Jan 23, 2003
30
US
Below is code I am working with that I got from another post.
I am having troubles "breakin it down". How exactly do I apply the code for the file path AND name of database/table I want to import into current d/base?
AND - I would like to run this from a command button on a form - Can this code be ran like this?

Thank you in advance!!!

Sub sExportExternal(strDBFrom As String, strDBTo As String, strGtwyinfo As String)
' Procedure to transfer a table from one external Access database to another
' Accepts:
' strDBFrom - the name and path of the database that contains the table to be exported from
' strDBTo - the name and path of the database that the table is to be exported to
' strTableName - the name of the table that is to be exported
On Error GoTo E_Handle
Dim objAccess As New Access.Application
With objAccess
.OpenCurrentDatabase (strDBFrom)
.DoCmd.TransferDatabase acExport, "Microsoft Access", strDBTo, acTable, strGtwyinfo, strGtwyinfo
.CloseCurrentDatabase
End With
sExit:
Exit Sub
E_Handle:
Select Case Err.Number
Case 3011 ' The table does not exist in the first database
MsgBox "'" & strTableName & "' does not exist in '" & strDBFrom & "'", vbOKOnly, "Transfer cancelled"
Case 3044 ' The database that we are transferring the table to does not exist
MsgBox "'" & strDBTo & "' does not exist.", vbOKOnly, "Transfer cancelled"
Case 7866 ' The database that we are transferring the table from does not exist
MsgBox "'" & strDBFrom & "' does not exist.", vbOKOnly, "Transfer cancelled"
Case Else
MsgBox Err.DESCRIPTION, vbOKOnly + vbCritical, Err.Number
End Select
Resume sExit
End Sub
 
Not much to break down:
If we remove the commenst and error handling for a moment, we get this:

Sub sExportExternal(strDBFrom As String, strDBTo As String, strGtwyinfo As String)

Dim objAccess As New Access.Application
With objAccess
.OpenCurrentDatabase (strDBFrom)
.DoCmd.TransferDatabase acExport,
"Microsoft Access",
strDBTo,
acTable,
strGtwyinfo,
strGtwyinfo
.CloseCurrentDatabase
End With



which is basically one line of code.

To run it from a commend button, just call the function like this:

cmdThing_Click()
sExportExternal("C:\source.mdb","C:\target.mdb", "TheTableName")


In your quoted example, the comments talk about strTableName AND strGtwyinfo but in fact it is strGtwyinfo that is passed as a parameter.
Replace strTableName with strGtwyinfo throughout, or vice versa, to make it work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top