General discussion

Locked

How do I copy an Access table with VB?

By Paul ·
I need to be able to copy the structure of an existing Access table in VB, checking to see if a couple of columns exist, if not, creating them, and saving them with a new name. Is this possible programatically?

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

ADOX

by onbliss In reply to How do I copy an Access t ...

Yes it is possible. Check out ADOX and ADO.
Here is an useful link: http://www.4guysfromrolla.com/webtech/013101-1.shtml

Collapse -

Why?

by alan williams In reply to How do I copy an Access t ...

Why do you need to this? The standard approach is to have 2 tables, the first containing the static data (and the primary key), the seccond containing the column name and data for that column (and the foreign key}. Then you use a query to join the tables back again. You can add the second table multiple times using an 'Alias' for the table (ie table2 as [NewColumn])

Collapse -

Copy Access Table in VB

by kargall In reply to How do I copy an Access t ...

Yes this is all possible, but the solution is too complicated for an email. Send me the specifics.

Collapse -

Try this one out

by amartyat In reply to How do I copy an Access t ...

Add an ADO Control with Datagrid control to access the Tables in Access Database (*.mdb) then to add and save with a new name use ccdlgcontrol to save
and sql Create Statement to create new db. If it works plz do drop a line at amartyat@gmail.com

Collapse -

field exists, if not create them.

by thydzik In reply to How do I copy an Access t ...

from my understanding you want to check if fields exist, and if they don't you would like to create them.

to see if fields exist, use the following function:
Function fieldExists(s As String, ByRef tablename As String) As Boolean
Dim temp As String
On Error Resume Next
temp = CurrentDb.TableDefs(tablename).Fields(s).Name
If Err.Number = 0 Then
fieldExists = True
ElseIf Err.Number = 3265 Then
fieldExists = False
Else
fieldExists = False
End If
End Function

to create a field you would use something like this:
db.TableDefs(tablename).Fields.Append db.TableDefs(tablename).CreateField(param, dbText, 25)

finally, if you want to save this table as a different name, you should make a copy of the table at the start, using the method
DoCmd.CopyObject

Back to IT Employment Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums