How can I reach Collections of an external DB via code (VBA)

A

Alp

How can I get to the collections such as forms, modules, etc of an external
database through VBA?
Is it possible to use SaveAsText on these?

Thanks in advance.

Alp
 
A

Allen Browne

With OpenDatabase(), you can get at the Documents in the Containers of
another database, but I doubt you could use SaveAsText since that just
accepts an object name and assumes the object is in the current database
 
A

Alp

Hi Allen,

Yes, I can get to retriving object names, etc. but can't get the SaveAsText
part to work as you have indicated. Can you think of a work-around? I hate
to go into the code in each, import the module that would do it...
I am just trying to go through a few (about15-20) copies of an mdb to sort
out differences in them. I know there are things I could purchase but just
want to try and do it myself and i.a.w. my needs. This set of files belong
to the time I made the mistake of not keeping track of what has been
modified/added etc. and unfortunately now I need the info!

Thanks,

Alp
 
A

Allen Browne

Nothing obvious. If you are writing a utility, I guess you could import the
forms from 2 versions, and delete them when done. Crass, but it should get
to any properties.

Beyond that you might be looking at spawning another instance of Access and
trying to manage it.

Or it may be possible to use the TSOON utility from www.trigeminal.com to
open another database, and pass control back to the original again.
 
A

Alex Dybenko

Hi,
SaveAsText is a method of application object, so as soon as you get a
reference to application - you can use SaveAsText.
 
A

Alp

Hi Alex,

I do get the reference to the application since I can obtain object names,
DateCreated, etc... But can not use the Application.SaveAsText, it is now
returning an error "You canceled the previous operation."
Code in question is:
------------code start-------------
Public Function dbObjeDets()
Dim db As DAO.Database
Dim strPath As String
Dim cnt As Container
Dim doc As Document

strPath = Forms!fr_ShowDBdetails!filename
Set db = OpenDatabase(strPath, True, True) 'ws.OpenDatabase(strPath, True,
True)

Set cnt = db.Containers("Forms")
On Error GoTo dbObjeDets_Err
For Each doc In cnt.Documents
Application.SaveAsText acForm, doc.Name, lokasyon & doc.Name &
".txt"
'Debug.Print doc.Name & ", Create:" & doc.DateCreated & ", Update:"
& doc.LastUpdated
Next doc

dbObjeDets_Err:
MsgBox Err.Description


Set db = Nothing
Set rs = Nothing
Set cnt = Nothing

End Function
----------------------code end---------------
"lokasyon" is a function that returns the full path of the database opened
less the file name. The commented Debug.Print is working if uncommented (and
the Application.SaveAsText.... commented of course)

The part from "Set cnt = ...." onwards works without a hitch when run within
the database which I am trying to get results out of.

What am I doing wrong?

Thanks in advance,

Alp
 
A

Alex Dybenko

Hmm, where do you run this code?
what i meant:

dim app as access.application
set app=createobject("access.application")
app.opendatabase ...
app.saveastext ...
 
A

Alp

If I run it within the database itself, all is fine. I do get the output I
want. The problem starts when I want to run it from an external database. I
get nothing...

Alp

I'll also try your implied suggestion
 
A

Alp

Hi Alex,

Still can't get anywhere. When I try to use app.opendatabase I get an error.
Actually I can't find such under application. I only see OpenAccessProject
and OpenCurrentDatabase thus I get the error.

Looks like I should give up trying to get this working...

Alp
 
A

Alex Dybenko

hi,
here a proc which works fine at me:
Sub SaveForm()
Dim app As Access.Application


Set app = CreateObject("Access.application")
app.OpenCurrentDatabase "D:\db1.mdb"
app.SaveAsText acForm, "Form1", "D:\form1.txt"

app.Quit

End Sub

HTH
 

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