Access Object Collections

D

Dan

Looking for documentation on manipulating Access object
collections(tables,queries,etc.). Want to automate
creation of new tables,queries,etc from 'templates' of
these objects. Currently, performing this process manually
(save as, changing names, updating criteria within the
copied object,etc). According a few periodical articles,
it appears possible, but I'm not seeing the ability to
take my changes down to the desired granularity. Extensive
documentation would help. OR, are there any third party
products available to allow doing this type of
manipulation?

As always, thanks in advance.

Dan
 
D

Dirk Goldgar

Dan said:
Looking for documentation on manipulating Access object
collections(tables,queries,etc.). Want to automate
creation of new tables,queries,etc from 'templates' of
these objects. Currently, performing this process manually
(save as, changing names, updating criteria within the
copied object,etc). According a few periodical articles,
it appears possible, but I'm not seeing the ability to
take my changes down to the desired granularity. Extensive
documentation would help. OR, are there any third party
products available to allow doing this type of
manipulation?

As always, thanks in advance.

Simply copying objects from templates can be accomplished by
DoCmd.CopyObject, or you can import objects using DoCmd.TransferDatabase.
There are different methods of modifying them, depending on the type of
object. If you describe in more detail what you want to do, maybe we could
give you some examples.
 
D

Dan

-----Original Message-----


Simply copying objects from templates can be accomplished by
DoCmd.CopyObject, or you can import objects using DoCmd.TransferDatabase.
There are different methods of modifying them, depending on the type of
object. If you describe in more detail what you want to do, maybe we could
give you some examples.
Dirk,

Thanks for the response. I've experimented with the
DoCmd's you mentioned and they will very much be a part of
this process. What I'm ultimately looking for is the
ability to change properties of the objects as in: 1)
within the query 'templates' we now have a hardcoded
selection criteria 'SF0000'. When we create a new
application, one of the steps is we copy the query
SF0000_00_50_SQ(template) as SF1000_00_50_SQ(new
application query) where the '1000' is the number of the
new application(the next would be 1001, etc). Within this
query is an application specific selection criteria
initially entered as 'SF0000' within the template which
needs to be changed to 'SF1000'. As indicated earlier, we
perform this step manually. Would like to automate
changing this 'criteria property'(if it exists and can be
manipulated) with VBA. 2) We also have documentation
within the Description for the query Properties that
requires changing to reflect control number/general
description for the new application. Again, we would like
to automate changing these values as well. There are
numerous other properties we would like to change within
other objects(forms, reports, & macros) in a similar
fashion.

Hope this gives you a better idea of what our intentions
are. This process takes approximately 20-30 minutes for
each new application we create. Would be a great time
saver if we could automate these changes we now perform
manually.

Again, thanks for any assistance you can provide.

Dan
 
D

Dirk Goldgar

See comments interspersed with original text.

Dan said:
Thanks for the response. I've experimented with the
DoCmd's you mentioned and they will very much be a part of
this process. What I'm ultimately looking for is the
ability to change properties of the objects as in: 1)
within the query 'templates' we now have a hardcoded
selection criteria 'SF0000'. When we create a new
application, one of the steps is we copy the query
SF0000_00_50_SQ(template) as SF1000_00_50_SQ(new
application query) where the '1000' is the number of the
new application(the next would be 1001, etc). Within this
query is an application specific selection criteria
initially entered as 'SF0000' within the template which
needs to be changed to 'SF1000'. As indicated earlier, we
perform this step manually. Would like to automate
changing this 'criteria property'(if it exists and can be
manipulated) with VBA.

There's no "criteria" property, but if I understand you correctly you
can probably do what you want with DAO (assuming you're working with an
..mdb file) by manipulating the .SQL property of the QueryDef object that
represents the new stored query. For example, assuming that dbNewApp is
a Database object variable currently set to the new application
database, and the query named "SF1000_00_50_SQ" has already been created
by copying its template, then *probably* you could use a code snippet
similar to this:

' ... assuming dbNewApp has already been set

Dim qdf As DAO.QueryDef

Set qdf = dbNewApp.QueryDefs("SF1000_00_50_SQ")
qdf.SQL = Replace(qdf.SQL, "SF0000", "SF1000")
Set qdf = Nothing

That could give you problems if the string "SF1000" occurs as part of
something else in the SQL, but you get the idea. If necessary, you
could parse the SQL statement and operate only on carefully chosen
pieces, but that would be more complicated.

2) We also have documentation
within the Description for the query Properties that
requires changing to reflect control number/general
description for the new application. Again, we would like
to automate changing these values as well. There are
numerous other properties we would like to change within
other objects(forms, reports, & macros) in a similar
fashion.

If the Description property already exists for the new query (because it
was copied from a template that had that property), then you can modify
it in a similar manner, as part of the same code:

' ... assuming dbNewApp has already been set

Dim qdf As DAO.QueryDef
Dim strDesc As String

Set qdf = dbNewApp.QueryDefs("SF1000_00_50_SQ")

With qdf

' Fix the SQL of the query.
.SQL = Replace(.SQL, "SF0000", "SF1000")

' Fix the Description property. If the property doesn't exist,
' we'll create it.
On Error GoTo Property_Error
strDesc = .Properties("Description")
strDesc = Replace("<CTLNO>", strControlNumber)
strDesc = Replace("<GENDESC>", strGeneralDescription)
.Properties("Description") = strDesc
PropertyResume:
On Error GoTo Your_Original_Error_Handler
End With


Set qdf = Nothing

Exit_Point:
Exit Sub

Property_Error:
If Err.Number = 3270 Then
strDesc = strControlNumber & " : " & strGeneralDescription '
or whatever
qdf.Properties.Append
qdf.CreateProperty("Description",dbText,"My property")
Resume PropertyResume
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End If
Hope this gives you a better idea of what our intentions
are. This process takes approximately 20-30 minutes for
each new application we create. Would be a great time
saver if we could automate these changes we now perform
manually.

I hope that gives you some ideas.
 
D

Dan

Dirk,

Thanks again!!! I will definitely be experimenting with
these suggestions. I see lots of potential to automate a
considerable number of our existing manual steps. You've
already reduced our turnaround a bunch!

Dan
 

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