473,378 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

need help with importing a Table from another access database in code

I have code to allow the user to select any .mdb of his choice on the HD,
but how do I then let him select a table from within this .mdb and then
create a destination table of a name that I assign in code.

DoCmd.TransferDatabase acImport, "Microsoft Access", anymdb, acTable,
anychoicetable, "fixedtablename"

So I would like this command to prompt the user so the user can select the
table
Thanks in advance
Nov 12 '05 #1
3 1873
Danny,

Look at TableDef in the help file. You will need to use the TableDef collection
to get a list of the tables in the .mdb. You will then have to write some code
where the user can select the table name from the collection and assign it to a
string variable such as SelectedTbl. Then in your TransferDatabase expression,
you will put SelectedTbl where you have anychoicetable.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Danny" <da********@hotmail.com> wrote in message
news:D2**********************@news4.srv.hcvlny.cv. net...
I have code to allow the user to select any .mdb of his choice on the HD,
but how do I then let him select a table from within this .mdb and then
create a destination table of a name that I assign in code.

DoCmd.TransferDatabase acImport, "Microsoft Access", anymdb, acTable,
anychoicetable, "fixedtablename"

So I would like this command to prompt the user so the user can select the
table
Thanks in advance

Nov 12 '05 #2
Danny,

Here's some code by Joe Black I just found in another newsgroup. It's almost
exactly what you need!

Steve
PC Datasheet

I use the following code to populate a combo box with the table names in the
current database (excluding system tables):

'*** code start ***
Private Sub Form_Open(Cancel As Integer)
Dim strRowSource As String
Dim TblDef As TableDef

Set db = CurrentDb
For Each TblDef In db.TableDefs
If InStr(TblDef.name, "Sys") = 0 Then
strRowSource = strRowSource & "'" & TblDef.name & "';"
End If
Next
strRowSource = Left(strRowSource, Len(strRowSource) - 1)
cboTableDefs.RowSource = strRowSource

Set db = Nothing
End Sub
'*** code end ***

and when I select a table name from the combo box, the following code puts
all the field names from the selected table into a listbox:

'*** code start ***
Private Sub cboTableDefs_AfterUpdate()
Dim Feeld As Field
Dim strRowSource As String

If IsNull(cboTableDefs) Then Exit Sub

Set TblDef = db.TableDefs(cboTableDefs)
For Each Feeld In TblDef.Fields
strRowSource = strRowSource & "'" & Feeld.name & "';"
Next
strRowSource = Left(strRowSource, Len(strRowSource) - 1)
lstFields.RowSource = strRowSource
lstFields.Requery
End Sub
'*** code end ***

"Danny" <da********@hotmail.com> wrote in message
news:D2**********************@news4.srv.hcvlny.cv. net...
I have code to allow the user to select any .mdb of his choice on the HD,
but how do I then let him select a table from within this .mdb and then
create a destination table of a name that I assign in code.

DoCmd.TransferDatabase acImport, "Microsoft Access", anymdb, acTable,
anychoicetable, "fixedtablename"

So I would like this command to prompt the user so the user can select the
table
Thanks in advance

Nov 12 '05 #3

"PC Datasheet" <sp**@nospam.spam> wrote in message
news:wz**************@newsread2.news.atl.earthlink .net...
Danny,

Here's some code by Joe Black I just found in another newsgroup. It's almost exactly what you need!

Steve
PC Datasheet

I use the following code to populate a combo box with the table names in the current database (excluding system tables):

'*** code start ***
Private Sub Form_Open(Cancel As Integer)
Dim strRowSource As String
Dim TblDef As TableDef

Set db = CurrentDb
For Each TblDef In db.TableDefs
If InStr(TblDef.name, "Sys") = 0 Then
strRowSource = strRowSource & "'" & TblDef.name & "';"
End If
Next
strRowSource = Left(strRowSource, Len(strRowSource) - 1)
cboTableDefs.RowSource = strRowSource

Set db = Nothing
End Sub
'*** code end ***

and when I select a table name from the combo box, the following code puts
all the field names from the selected table into a listbox:

'*** code start ***
Private Sub cboTableDefs_AfterUpdate()
Dim Feeld As Field
Dim strRowSource As String

If IsNull(cboTableDefs) Then Exit Sub

Set TblDef = db.TableDefs(cboTableDefs)
For Each Feeld In TblDef.Fields
strRowSource = strRowSource & "'" & Feeld.name & "';"
Next
strRowSource = Left(strRowSource, Len(strRowSource) - 1)
lstFields.RowSource = strRowSource
lstFields.Requery
End Sub
'*** code end ***

"Danny" <da********@hotmail.com> wrote in message
news:D2**********************@news4.srv.hcvlny.cv. net...
I have code to allow the user to select any .mdb of his choice on the HD, but how do I then let him select a table from within this .mdb and then
create a destination table of a name that I assign in code.

DoCmd.TransferDatabase acImport, "Microsoft Access", anymdb, acTable,
anychoicetable, "fixedtablename"

So I would like this command to prompt the user so the user can select the table
Thanks in advance



Thakns, this is great.

I will apply this my app.

Danny

Nov 12 '05 #4

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

Similar topics

4
by: Howard | last post by:
I am trying to use DoCmd.TranferSpreadsheet to import a spreadsheet into an Access table that's not the CurrentDB. I have the database open, but I don't see how to tell the TransferSpreadsheet...
9
by: Edward S | last post by:
I budget for a Project in an Excel sheet as illustrated below. The months below are usually a 2 year period i.e. 24 months, though it could be over 24 months depending upon a Project. I then...
1
by: Serious_Practitioner | last post by:
Good day - As you suggested, I got and used the right version of Jetcomp, and I also tried to run compact and repair a couple of times. I think that the compact and repair process doesn't fully...
3
by: Danny | last post by:
I have code to allow the user to select any .mdb of his choice on the HD, but how do I then let him select a table from within this .mdb and then create a destination table of a name that I assign...
9
by: cheryl | last post by:
I am relatively new to programming in Access for a multi user environment, and am having trouble figuring out if there is a way to accomplish one of our user requests. I am working on a multi...
3
by: pemigh | last post by:
A while back I imported tables to a new database via Files-->Get External Data --> Import... All was well for several months, and then the database started behaving badly in a couple of ways,...
1
by: thadson | last post by:
Hi, I'm trying to import specific cells from MS Excel 2000 spreadsheets to MS Access 2000 tables then move the spreadsheets to a different directory. I'm very new to this and I'm having trouble...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: upadhyayanuj | last post by:
Hi I have an error while uploading file and then importing it into my sql table The process cannot access the file 'c:\inetpub\wwwroot\FlowLine\Excel File\Fan_Details.xls' because it is being...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.