Connecting Tech Pros Worldwide Forums | Help | Site Map

Acc2K3: is there a way to programatically save form / module code to external files?

planetthoughtful
Guest
 
Posts: n/a
#1: Apr 30 '06
Hi All,

Just wondering if anyone can tell me if it's possible to
programatically save Access2003 code (ie code behind forms, as well as
class modules) to external files?

I'd like to use versioning software to keep track of code changes, but
this would require being able to save the files easily to *.cls and
*.bas files.

Any help appreciated!

Much warmth,

planetthoughtful
---
"lost in thought"
http://www.planetthoughtful.org1

Allen Browne
Guest
 
Posts: n/a
#2: Apr 30 '06

re: Acc2K3: is there a way to programatically save form / module code to external files?


The undocumented SaveAsText might give you what you want, e.g.:
SaveAsText acForm, "Form1", "C:\Form1.txt"

LoadFromText it the matching statement.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"planetthoughtful" <planetthoughtful@gmail.com> wrote in message
news:1146384953.153338.27060@u72g2000cwu.googlegro ups.com...[color=blue]
> Hi All,
>
> Just wondering if anyone can tell me if it's possible to
> programatically save Access2003 code (ie code behind forms, as well as
> class modules) to external files?
>
> I'd like to use versioning software to keep track of code changes, but
> this would require being able to save the files easily to *.cls and
> *.bas files.[/color]


planetthoughtful
Guest
 
Posts: n/a
#3: Apr 30 '06

re: Acc2K3: is there a way to programatically save form / module code to external files?


Hi Allen,

Thanks for the answer!

Here's some code, in case someone else looks for the same thing at a
later date:

Sub SaveAccessObjectsToFile()
Dim obj As AccessObject
Dim dbs As Object
Dim dbd As Object
Dim filesaveloc as string
Set dbs = Application.CurrentProject
Set dbd = Application.CurrentData
filesaveloc = "C:\Documents And Settings\" ' Edit to your preferred
save location
For Each obj In dbs.AllForms
SaveAsText acForm, obj.Name, filesaveloc & obj.Name & ".cls"
Next
For Each obj In dbs.AllModules
SaveAsText acModule, obj.Name, filesaveloc & obj.Name & ".bas"
Next
For Each obj In dbd.AllQueries
SaveAsText acQuery, obj.Name, filesaveloc & obj.Name & ".sql"
Next
End Sub

Note: I haven't been able to save table objects using "SaveAsText
acTable", but this may be because the tables are linked rather than
local to the mdb file executing this code.

Thanks again!

Much warmth,

planetthoughtful
---
"lost in thought"
http://www.planetthoughtful.org

david epsom dot com dot au
Guest
 
Posts: n/a
#4: May 1 '06

re: Acc2K3: is there a way to programatically save form / module code to external files?


There is no way to save as text the table objects. The best you
can do is use the SaveAsText command with option 6 to save a
binary copy of the database with it's table objects, minus
all the stuff exported by the other options.

This is the say MS Source Safe handles the database: every
thing else as text, tables and data in a single binary object.

Access 2003 has extended XML methods, and you may be able
to find code to document the tables and data as XML.

(david)

"planetthoughtful" <planetthoughtful@gmail.com> wrote in message
news:1146401880.388514.105830@i40g2000cwc.googlegr oups.com...[color=blue]
> Hi Allen,
>
> Thanks for the answer!
>
> Here's some code, in case someone else looks for the same thing at a
> later date:
>
> Sub SaveAccessObjectsToFile()
> Dim obj As AccessObject
> Dim dbs As Object
> Dim dbd As Object
> Dim filesaveloc as string
> Set dbs = Application.CurrentProject
> Set dbd = Application.CurrentData
> filesaveloc = "C:\Documents And Settings\" ' Edit to your preferred
> save location
> For Each obj In dbs.AllForms
> SaveAsText acForm, obj.Name, filesaveloc & obj.Name & ".cls"
> Next
> For Each obj In dbs.AllModules
> SaveAsText acModule, obj.Name, filesaveloc & obj.Name & ".bas"
> Next
> For Each obj In dbd.AllQueries
> SaveAsText acQuery, obj.Name, filesaveloc & obj.Name & ".sql"
> Next
> End Sub
>
> Note: I haven't been able to save table objects using "SaveAsText
> acTable", but this may be because the tables are linked rather than
> local to the mdb file executing this code.
>
> Thanks again!
>
> Much warmth,
>
> planetthoughtful
> ---
> "lost in thought"
> http://www.planetthoughtful.org
>[/color]


Lyle Fairfield
Guest
 
Posts: n/a
#5: May 1 '06

re: Acc2K3: is there a way to programatically save form / module code to external files?


This is a JScript that saves a db's tabes as text (in two formats). It
should not take a lot to translate it over to VBA.

var r=new ActiveXObject('ADODB.Recordset');
var s=new ActiveXObject('ADODB.Recordset');

s = c.OpenSchema(20, Array(null, null, null, "Table"))
while(!s.EOF){
ts=s.Collect('TABLE_NAME');
if(ts.substr(0,2)!='dt'){
r=c.Execute('SELECT * FROM [' + ts + ']');
try{
f.DeleteFile('C:/DB_51315Backups/'+ts+'.adtg');
f.DeleteFile('C:/DB_51315Backups/'+ts+'.xml');
}
catch(e){
}
r.Save('C:/DB_51315Backups/'+ts+'.adtg',0)
r.Save('C:/DB_51315Backups/'+ts+'.xml',1)
}
s.MoveNext
}

Closed Thread