export forms to other databases

Bram de Groot

New member
Local time
Today, 09:02
Joined
Feb 18, 2004
Messages
7
I want to export forms to other databases. I managed to export tables with:

Dim db as DAO.database
Dim tdf As DAO.TableDef
For Each tdf In db.TableDefs
DoCmd.TransferDatabase acExport, "Microsoft Access", strdbpath, acTable, tdf.Name, tdf.Name
Next

I want to do the same thing with forms but I can't figure out how to do this, because you can't use something like:

Dim form as DOA.FormDef
For each form........etc.

Can anyone help me out?
Thanks!
Bram de Groot
 
Bram de Groot said:
I want to do the same thing with forms but I can't figure out how to do this, because you can't use something like:

Dim form as DOA.FormDef
For each form........etc.

Can anyone help me out?
Thanks!
Bram de Groot
Well, not exactly, because Forms are not DAO objects, they are Access objects. Here's some sample code:
Code:
Sub PrintFormNames()
Dim frm As Access.Form
For Each frm In Access.Forms
    Debug.Print frm.Name
Next frm
End Sub
 
I used the suggested code in my export module but I don't see any results. No forms are exported, but it doesn't give errors. I tried to print the frm.names with your sample code, but that also doesn't seem to work. I don't see the frm.names printed in the directview. I'm just a beginner with VB so I hope you can be more specific? Thanks for your time.

Bram de Groot
 
Out of interest, can I ask why you are going to all this effort to transfer objects between databases?
 
Mile-O-Phile said:
Out of interest, can I ask why you are going to all this effort to transfer objects between databases?

For some logistic reason I thought it would be better to split my database into separate databases with the same forms and since I don't really like to copy/paste and rename for x times I was looking for a way to create new db's and export all tables and forms in VB.
Now, I reconsidered the idea and will hold on to my front/ backend database.

But I am still curious why the suggested code doesn't work.

Bram de Groot
 
Bram de Groot said:
But I am still curious why the suggested code doesn't work.

It does work but it's only an example of looping through the Forms collection. What the code is doing is printing the name of each form to the Immediate Window.

What you need to send the form to another database is the CopyObject method.
 
Mile-O-Phile said:
What you need to send the form to another database is the CopyObject method.

Or use the TransferDatabase method again, this time for forms.
 

Users who are viewing this thread

Back
Top Bottom