copy forms between databases

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am in a access database and want to import all the forms from another
access database into my current database. I will not know the names of the
forms beforehand. I am having problems making it work. Does anyone know how
to do this, or have a suggestion where to start?
 
On the File menu, Get External Data, then follow the prompts. You'll get
something similar to the database window, for the database you specify,
select all the forms and import them.

Larry Linson
Microsoft Access MVP
 
Caveat: I have not used this in the 'real world'. I have only tested it
breifly for this reply. Use in a production environment strictly at your own
risk.

Public Sub ImportForms()

Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = DBEngine.OpenDatabase(CurrentProject.Path & "\db31.mdb")
Set rst = db.OpenRecordset("SELECT MSysObjects.Name FROM MSysObjects
WHERE MSysObjects.Type = -32768")
Do Until rst.EOF
DoCmd.TransferDatabase acImport, "Microsoft Access", db.Name,
acForm, rst.Fields("Name"), rst.Fields("Name")
rst.MoveNext
Loop
rst.Close
db.Close

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
he means from inside VBA, not from the command menu.

Perhaps so, but it is not patently obvioius to this casual observer that is
what was asked. In any case, it is likely a very poor design to import forms
at runtime. That is why I gave the "manual answer" and am waiting for a
response from the original poster. If the answer is as yours, I will ask for
clarification as to what the OP is trying to accomplish that _requires_
importing forms from code.

It is possible, of course, that there is some situation where there is a
compelling reason to do this, but I've been using Access daily since early
1993 and can't imagine any situation where it would be either needful or
desirable.

If it were necessary, it would involve opening the other database in code,
running its Containers to find the Forms, and copying them, probably with
CopyObject. It is possible, but that doesn't mean it is desirable nor that
it should be encouraged.

Larry Linson
Microsoft Access MVP
 
I am sorry I wasn't as clear as I could have been Larry.

I am trying to craft an update routine that will copy changes in the program
to a users copy of the database. I want to be able to protect any changes
made by the user to the original format of the program so I don't want to
just copy everything across and over right the existing.

The tables are the most important part, so I copy the fields, etc without
disturbing any user defined fields that have been added. I was able to do
that without much of a problem. They are much easier to access from one
database to another.

With the forms I want to be able to copy the new instance of the form from
the "Setup" database to the user database. Since I am initiating this from
the user side, I need to be able to get the name of the forms in the "Setup"
database, determine if there is an existing form by that name in the user
database, if there is, delete it, then copy the new instance of the form from
the "Setup" database to the user database, using the same name.

I tried the way that Brendan Reynolds suggested, and it works ok, except
that the form that is copied doesn't have its associated module with it. The
form is in the database window, and you can click on the design button and it
opens it, but there are is no code module when I look at the events, etc.

If there is a better way to do this, I would be happy to entertain it.
 
I just double checked, and in my tests the code module is copied along with
the form.

Note that I'm not recommending this approach. I think the only safe approach
is that the user stop making any design changes, and send you his/her
complete copy of the application MDB. You make your changes and send it
back. But if you still want to pursue this approach, there must be some
reason why the form's code modules are not copied along with the form in
your tests, because they certainly are in mine.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Back
Top