to refer to module in external db

?

.

Front-end db is large, and update usually is to the code only. Therefore
my code exports standard module from dev db,
and db 'A" on destination computer imports it. "A" exists only for purpose
of replacing module in target db "B".

I cannot find syntax to refer, in A's code, to **module** in B.
 
T

TC

The Modules collection of the reference to db B?

But why bother exporting individual modules? Since you database has a front
end/back end structure, why not just give them a whole new copy of the front
end database file?

HTH,
TC
 
?

.

The Modules collection of the reference to db B?

Did you do it?
It's what I had been trying. To all appearances, doesn't exist.

why not just give them a whole new copy

I lead with the why not:
Takes too long via modems.
And now I find a fatal reason: non-text files do not transfer intact
through Earthlink's FTP. Even zips are unzippable.
Something stinks there.

So, lacking a reference to module in non-current db, I am stuck.

(Access 97.)
 
M

Marshall Barton

. said:
Did you do it?
It's what I had been trying. To all appearances, doesn't exist.


It sounds like there's a misunderstanding here. I think
TC's point is to use code like:

Dim dbOther As DAO.Database
Dim mdl As Module
Set dbOther = OpenDatabase("path to other db")
Set mdl = OpenModule("nameofmodule")

On the other hand, I don't see how that can help with your
original problem. Maybe you should look into using the
Modules Container to remove the existing module Document so
you can then use either TransferDatabase or SendObject to
copy the module.
 
T

TC

Marshall Barton said:
It sounds like there's a misunderstanding here. I think
TC's point is to use code like:

Dim dbOther As DAO.Database
Dim mdl As Module
Set dbOther = OpenDatabase("path to other db")
Set mdl = OpenModule("nameofmodule")


Close! I was actually thinking:

set mdl = dbOther.Modules("nameofmodule")

Unfortunately I don't have Access on the PC from which I post, to check.

Cheers,
TC
 
T

TC

Dirk Goldgar said:
No, the Modules *collection* is an Access object, not a DAO thing.
Marshall's idea of using the Modules *container* is the only way I can
think of to get at it. That needs a reference like

Dim doc As DAO.Document
Set doc = dbOther.Containers("Modules").Documents("nameofmodule")


Ah, you're quite right. But, he will not be able to access the module's
content< via the document object :)

TC
 
D

Dirk Goldgar

TC said:
Close! I was actually thinking:

set mdl = dbOther.Modules("nameofmodule")

Unfortunately I don't have Access on the PC from which I post, to
check.

No, the Modules *collection* is an Access object, not a DAO thing.
Marshall's idea of using the Modules *container* is the only way I can
think of to get at it. That needs a reference like

Dim doc As DAO.Document

Set doc = dbOther.Containers("Modules").Documents("nameofmodule")
 
D

Dirk Goldgar

TC said:
Ah, you're quite right. But, he will not be able to access the
module's

Right, but he can test for its existence. I don't think he's going to
be able to do much useful work, though, without opening a second
instance of Access by automation.
 
?

.

I have to go lie down.

Just kidding; this is a fabulous exchange. Whatever the consensus
(apparently unreached as of yet), I will try it. Provided that Access 97
is capable of it.
 
T

TC

I have to go lie down.

Nicely put :)

Just kidding; this is a fabulous exchange.

Dirk and I are planning to contest the middleweight title at Madison Gardens
later this year.

Whatever the consensus (apparently unreached as of yet), I will try it.
Provided that Access 97 is capable of it.

We are all fairly clear on what can & can't be done. I think we are not
clear on what you >actually want< to do. What exactly do you actually want
to do with the modules in the other database?

TC

(snip)
 
?

.

What exactly do you actually want
to do with the modules in the other database?

TC


To replace standard module, programatically.
To provide user-initiated, automated program update.

Since module cannot replace itself without crashing,
something external to it must do the replacing.
 
E

Emilia Maxim

---------- ". said:
To replace standard module, programatically.
To provide user-initiated, automated program update.

Charles,

why not simply overwrite the frontend? If it's a network, there are
different strategies like for ex copy from server in the login script.

Updating only parts of the app is a much bigger risk. What if it's not
successful, what if some modules get copied, and some not?

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
T

TC

. .net> said:
To replace standard module, programatically.
To provide user-initiated, automated program update.

Since module cannot replace itself without crashing,
something external to it must do the replacing.


Ok, I remember now. I won't try to guess the code on this. I'll take a look
tonight, & post back within 48 hours unless someone beats me to it.

TC
 
?

.

non-text files do not transfer intact through Earthlink's FTP.

FYI:
Using XP's util.
Today I used 3rd-party FTP util,
and it xfers same binary files properly.

(Time required remains as reason for wanting to xfer module only.)
 
T

TC

Sorry this is taking a while! I've been busy for the last few days & also
tonight. I'll endevour to try your code tomorrow (Monday, wghere I live) &
post back ASAP unless someone else beats me to it.

TC
 
T

TC

. .net> said:
To replace standard module, programatically.
To provide user-initiated, automated program update.

Since module cannot replace itself without crashing,
something external to it must do the replacing.


Ok!

Sorry this has taken a while, but I do not have Access on this PC. Most of
my replies are from memory. Your question was a bit too tricky to answer
from memory. And I have been busy recently, so although I have continued to
answer other questions, I have not had time to investigate your question
properly.

Here is what you need.


(1) Create a database named OLD.MDB that contains a module named AAA that
contains a public procedure named Z that displays a message. (Say, "Original
Z!") Open that db, go to the debug window (ctrl-G), type "Z" (without the
quotes) and press return. The "original" message should be displayed. Now
close that database.

(2) Now create a second database NEW.MDB in the same folder as OLD.MDB. Open
NEW.MDB, and add a module named BBB that contains a public procedure also
named Z, that displays a different message. (Say, "New Z!") Go to the debug
window (ctrl-G), type "Z" (without the quotes) and press return. The "new"
message should be displayed.

(3) Now add a new module, named whatever you like, to NEW.MDB, containing
the following code:


'----- START CODE -----

Option Explicit
Option Compare Database

' This procedure replaces module AAA in database OLD.MDB, with the
' content of module BBB from the current database. It assumes that:
' o OLD.MDB is in the current directory;
' o OLD.MDB does have a module named AAA;
' o the current db does have a module named BBB.

Public Sub UPDATE()
Dim sOldDB As String

' locate the old db.
sOldDB = DBEngine(0)(0).Name
While Right$(sOldDB, 1) <> "\": sOldDB = Left$(sOldDB, Len(sOldDB) - 1):
Wend
sOldDB = sOldDB & "OLD.MDB"
msgbox "UPDATING " & sOldDB

' delete module "AAA" from that db. In doing this, I'm assuming that
' CopyObject will fail if there is an existing object of that name.
' If that is not the case - and CopyObject will overwrite an existing
' object of the same name - omit the next code.

Dim oAccess As Object
Set oAccess = CreateObject("Access.Application")
With oAccess
.OpenCurrentDatabase sOldDB
.DoCmd.DeleteObject acModule, "AAA"
' delete more modules here, if required.
End With
oAccess.Quit
Set oAccess = Nothing

' now copy module "BBB" from THIS db, to module "AAA" of the old db.

DoCmd.CopyObject sOldDB, "AAA", acModule, "BBB"
' copy more modules here, if required.

MsgBox "DONE"

End Sub

'----- END CODE -----


(4) Now close everything, to get to the situation where the user has
downloaded NEW.MDB, and is ready to use it to update his OLD.MDB.

(5) Open NEW.MDB, go to the debug window (ctrl-G), type "UPDATE" (without
the quotes) and press return. This will replace the content of module AAA in
OLD.MDB (in that folder), with the content of module BBB from NEW.MDB. You
can confirm this by closing NEW.MDB, opening OLD.MDB, going to the debug
window, then typing "z" (without the quotes) and pressing return. This will
display the NEW message (perhaps "New Z!"), not the old one ("Original Z!").

When you've got this working, you could extend it as appropriate. For
example, the two MDB's might be in different directories. And, the new & old
modules will probably have the same name - not different ones.

Also, you should consider what to do when errors occur. For example, what if
the process successfully deletes the old module(s) from OLD.MDB, but fails
to add the new module(s) from NEW.MDB? Then you would need some way to go
backwards to the original OLD.MDB, to get the system working again.

HTH,
TC
 
T

TC

TC said:
Sorry this is taking a while! I've been busy for the last few days & also
tonight. I'll endevour to try your code tomorrow (Monday, wghere I live) &
post back ASAP unless someone else beats me to it.


Now answered in this thread.

TC
 
K

Kahuna

Excellent TC, great code as usual. Just one question, could this be applied
in a secure environment, such as a secure OLD.MDB?

What might the connection code look like for that?

This technique seems to be similar to that employed in the App 'Surgical
Strike' touted a couple of years ago as an Access auto update / patch tool,
but that app couldn't cope with secure environments so it seems to have
slipped below the surface - maybe its still around?
 
?

.

Set oAccess = CreateObject("Access.Application")
With oAccess
.OpenCurrentDatabase sOldDB
.DoCmd.DeleteObject acModule, "AAA"
End With
oAccess.Quit

Although not a reference to module in external db,
I do not complain, because deletion stopped Access' crashing,
allowing the things that I had been trying (incl DoCmd.CopyObject)
to proceed.

Everybody, we raise TC onto our shoulders for a hero's ride.
 

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