Replace form in external mdb

A

AndrewDB

Hi All. I need to replace a form and attached vb procedures situated in an
external mdb using vba. I can use copyobject but as a form with that name
already exists I get an error.
 
A

AndrewDB

Thanks Ken. If the form already exists in that database I need a message
informing me so that I can respond -Replace? Yes/No. If yes I need to first
delete the original form before copying the new one across.

By the way what does [MVP] stand for?

Best Regards
 
K

Ken Snell [MVP]

You can use code such as this to test if the form is there:

Dim aca As Access.Application
Dim frm As Form
Dim intReply As Integer
Set aca = New Access.Application
aca.OpenCurrentDatabase "C:\MyFolder\MyDBmdb"
intReply = vbYes
For Each frm In aca.CurrentProject.AllForms
If frm.Name = "NameOfFormInOtherDB" Then
intReply = MsgBox("Form exists. Do you want to replace it?", _
vbYesNo, "Replace Form?")
Exit For
End If
Next frm
aca.CloseCurrentDatabase
aca.Quit
Set aca = Nothing
If intReply = vbYes Then
DoCmd.TransferDatabase acExport, "Microsoft Access",
"C:\MyFolder\MyDBmdb", _
acForm, "NameOfFormInYourDB", "NameOfFormInOtherDB"
End If


--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top