PC Review


Reply
Thread Tools Rate Thread

Change form design via VBA

 
 
Carl Colijn
Guest
Posts: n/a
 
      25th Mar 2006
Hi all,

I want to change the design of some of my forms via a VBA routine; to be
specific: I want to clear the RecordSource property. Running this routine
will be part of my roll-out procedure list (I need the RecordSource to be
empty for distribution and later set dynamically in OnLoad, but sometimes
the actual used runtime setting might get saved in when I switch to form
design when modifying the form).

I'm currently using the following technique:
Call DoCmd.OpenForm(sFormName, acDesign)
Forms(sFormName).RecordSource = ""
Call DoCmd.Save(acForm, sFormName)
Call DoCmd.OpenForm(sFormName)
Call DoCmd.Close(acForm, sFormName)

but this invariantly crashes Access with the following error:
Microsoft Visual C++ Runtime Library

Runtime Error!
Program D:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE
abnormal program termination

I'm using Access 2003.

Is there an alternative way to set a form's recordsource via VBA code? If I
have to process each form manually before each roll-out, I fear some of them
might slip through from time to time...

Thanks in advance,
Carl Colijn

--
TwoLogs - IT Services and Product Development
A natural choice!
http://www.twologs.com
ShellDispenser: restarting Windows Explorer couldn't be easier!
http://www.twologs.com/en/products/shelldispenser.asp


 
Reply With Quote
 
 
 
 
TC
Guest
Posts: n/a
 
      25th Mar 2006
Carl, this is off the top of my head, but I've written tons of code
like this in the past, and I'm sure that it would work for you.

(untested)

' close all forms before running this code.
dim con as container, doc as document
set con = dbengine(0)(0).containers![forms]
for each doc in con.documents
' doc.name is the name of the next form in the database.
docmd.openform doc.name, acDesign '<<< (1)
forms(doc.name).recordsource = "" '<<< (2)
docmd.close acform, doc.name, acSave '<<< (1)
next
set con=nothing

Note:
(1) Check the parameters: I don't have Access here to check.
(2) Try NULL, if the empty string ("") doesn't work. I can't remember
whether the recordsource property is a variant, or a string.

HTH,
TC (MVP Access)
http://tc2.atspace.com

 
Reply With Quote
 
Carl Colijn
Guest
Posts: n/a
 
      25th Mar 2006
In news:(E-Mail Removed),
TC <(E-Mail Removed)> typed:
> Carl, this is off the top of my head, but I've written tons of code
> like this in the past, and I'm sure that it would work for you.
>
> (untested)
>
> ' close all forms before running this code.
> dim con as container, doc as document
> set con = dbengine(0)(0).containers![forms]
> for each doc in con.documents
> ' doc.name is the name of the next form in the database.
> docmd.openform doc.name, acDesign '<<< (1)
> forms(doc.name).recordsource = "" '<<< (2)
> docmd.close acform, doc.name, acSave '<<< (1)
> next
> set con=nothing
>
> Note:
> (1) Check the parameters: I don't have Access here to check.
> (2) Try NULL, if the empty string ("") doesn't work. I can't remember
> whether the recordsource property is a variant, or a string.


Hi TC,

Thanks, this code works without crashing Access! The difference with the
code fragment I used was that I first performed a DoCmd.Save to save the
changes, then a normal DoCmd.Open to get the form out of design mode, and
then the final DoCmd.Close.

Don't know why I took these particular steps; I tried all sort of things
while the code kept crashing Access... But just a simple DoCmd.Close(...
Save) did the trick

Thanks again and have a nice weekend,
Carl

btw: an empty string works OK (at least, so far for me), and it's acSaveYes
or acSavePrompt; I used acSaveYes


 
Reply With Quote
 
TC
Guest
Posts: n/a
 
      25th Mar 2006
Ok, well done :-)

TC (MVP Access)
http://tc2.atspace.com

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can not change the design of the form in Outlook? =?Utf-8?B?UEpD?= Microsoft Outlook Contacts 0 20th Oct 2006 05:32 PM
Change Form Properties in Design Mode TedB Microsoft Outlook 1 9th Dec 2005 02:20 PM
Change form design after split =?Utf-8?B?TWF0dCBXLg==?= Microsoft Access 3 21st Nov 2005 05:02 PM
Form's design change =?Utf-8?B?QWppdA==?= Microsoft Excel Programming 0 16th Sep 2004 06:55 PM
cant change a form design eVELYN Microsoft Access Security 3 6th Nov 2003 11:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:35 PM.