By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,490 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,490 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Apr 30 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <pl**************@gmail.com> wrote in message
news:11*********************@u72g2000cwu.googlegro ups.com...
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.

Apr 30 '06 #2

P: n/a
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

Apr 30 '06 #3

P: n/a
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" <pl**************@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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

May 1 '06 #4

P: n/a
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
}

May 1 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.