Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting external forms 2

Status
Not open for further replies.

funger

Programmer
Joined
May 23, 2003
Messages
8
Location
US
Hi all!

I am trying to make a small 'patch' database that will replace items in a much larger 'master' database.

In this patch I need to replace two forms in the master database. I am able to use DoCmd.TransferDatabase to move the forms from the patch into the master, however I don't know how to delete the older forms from the master first.

I have scoured the help files, and the microsoft site with no success.

Please someone help me!! :)

Thanks in advance!
-Funger
 
I think this is what you are looking for.

DoCmd.DeleteObject acForm, "FormName"

Hope this helps.
 
Hi funger,

Part 1 of the Example below will Delete a Form Called "OldForm" in a Database Called "FE.mdb". This assumes "FE" to be in the same Folder as the Patch.mdb. If not you will have to specify a Folder.

Part2 will Copy a Form Called "NewForm" from the Patch.mdb to "FE.mdb" also Naming the Form "NewForm" in the "FE.mdb". By using the Setwarnings, if "NewForm" already Exists it will be Replaced without any User Interaction.

Dim appAccess As Access.Application
Dim frm As Form, strDB As String

On Error Resume Next
strDB = "FE.mdb"

'Part 1
Set appAccess = CreateObject("Access.Application.9")
appAccess.OpenCurrentDatabase strDB
appAccess.DoCmd.DeleteObject acForm, "OldForm"
appAccess.CloseCurrentDatabase
Set appAccess = Nothing


'Part 2
DoCmd.SetWarnings False
DoCmd.CopyObject strDB, "NewForm", acForm, "NewForm"
DoCmd.SetWarnings True



If you are just replacing existing Forms, then Part 2 is all you need.

Hi humbleprogrammer, sorry but funger needs to Delete a Form in an External DB. You had the right Method though. Good Luck.

Regards

Bill
 
Hi funger,

Small Amendment to get the Current Directory :

strDB = "FE.mdb" should read:

Access 97:
Dim Cdbs As String, dbs As String, Cdir As String
dbs = "Patch.mdb"
Cdbs = CurrentDb.Name
Cdir = Left(Cdbs, InStr(Cdbs, dbs) - 1)
strDB =Cdir & "FE.mdb"

Access 2000 +:
strDB = Application.CurrentProject.Path & "\FE.mdb”

I also forgot to say Replace "FE.mdb" with the Name of the Master Database.

I just posted an answer in another Thread and Realised that I hadn't given you 100% accurate info. Anyway you probably already know how to get the Current Directory.

Good Luck

Bill
 
billpower,

You ROCK! Thank you for your help. It's really been difficult trying to find help on this subject. :)
I was really close, but just couldn't get it to work. I was also using transferdatabase to move things around, and it just doesn't seem to work as well as CopyObject... is it multithreaded?

All is good in the world! Ha!

-Funger
 
Can I put in my 2p's worth:

Why bother with the hassle of deleting a form? If your database is split (and it really really really should) then just copy the new version over the old & all forms/reports/macros/modules will be updated.

hth


Ben

----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Hi oharab,

I was just about to ask funger what they meant about multithreaded. funger what do you mean "multithreaded" in relation to CopyObject. Thanks funger for such a nice reply, it makes it worthwhile trying to help getting responses like that. I wish Tek-Tips had been around when I was learning.

oharab, I agree with you and did point that out(extract below). Maybe you missed a bit, don't worry about it, I do it all the time.

'Part 2
DoCmd.SetWarnings False
DoCmd.CopyObject strDB, "NewForm", acForm, "NewForm"
DoCmd.SetWarnings True
If you are just replacing existing Forms, then Part 2 is all you need.


Good Luck

Bill
 
billpower, it just seems like VB continues on with the code before the object has been completley copied. I was having all sorts of problems.

And as far as the response goes... I don't think I could have been happier to see a useful response this morning. If I keep getting help like this, I will definatly contribute to this site!
:)
 
Hi again funger,

Try using the "DoEvents" Method, should solve yoor problem:

DoCmd.SetWarnings False
DoCmd.CopyObject strDB, "NewForm", acForm, "NewForm"
DoEvents
DoCmd.SetWarnings True

Good Luck

Bill
 
BillPower you are awesome!

If there is a question worth asking good chance its already been asked, and good chance BillPower offered a great approach.

thanks again.
 
in reference to the patch code above, can anyone expand on it to tell me how i would patch a password protected DB

because to patch one currently i have to have user unlock through VBA Editor before the patch.mdb file can run. since i know what the password is, i know there is got to be a way to unlock then lock as part of the patch.

any help very much appreciated.
 
Hi LikeThisName,

Thanks for the comments, much appreciated.

The amended code below should work ok with a password protected DB:

Dim appAccess As Access.Application, dbs As DAO.Database, strDB As String
On Error GoTo Err_Delete
strDB = Application.CurrentProject.Path & "\FE.mdb"
Set appAccess = New Access.Application
Set dbs = appAccess.DBEngine.OpenDatabase(strDB, False, False, ";PWD=1234")
appAccess.OpenCurrentDatabase strDB
appAccess.DoCmd.DeleteObject acForm, "OldForm"
appAccess.CloseCurrentDatabase
Set appAccess = Nothing
Set dbs = Nothing
Exit Sub
Err_Delete:
MsgBox "Error No. " & Err.Number & " - " & Err.Description

Once again, Thanks.

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top