Property sheet getting messed up (by VBA?)

bluegno

Registered User.
Local time
Today, 09:41
Joined
Nov 30, 2005
Messages
27
Here's my nightmare. I'm doing development on a large Access program (lots of VBA). One day I open the Access file and my forms are completely messed up. Property sheet values have changed everywhere... in the forms themselves and also in the controls.

Actually this has happened several times. One time it took a whole day to find and repair all the damage.

I suppose what I really need to do is have Form_Load code that assigns default values to all of the properties I could possibly care about, both in my forms and the controls within them.

But it would be helpful to know what is causing my properties to get overwritten in the first place. I have tried to intentionally reproduce the problem, but have had no success (or failure, depending on how you look at it).

Here is a simplified example. Say I have a form that has caption "x" and a button that changes the caption to y:

Code:
Private Sub y_Click()
 Me.Caption = "y"
End Sub

I've tried breakpoints and "bad exits" to try to get the y to "stick" (so that it's still there next time I open the Access file). But I can't seem to intentionally make it happen. Yet this is the exact type of thing that has occurred on several ocasions.

What could be the cause? Has anybody else encountered this?
 
Is there ANYWHERE in your code that uses

DoCmd.Save

or

DoCmd.Close acForm, "FormName", acSaveYes


If so, you want to get rid of those. Actually, in the second case you just want acSaveNo. The acSaveYes or DoCmd.Save are for saving design changes and not records.
 
Yes, I do have a DoCmd.Save. Could that really be the problem?

In the past I've questioned why the command is in the code. A while ago I even added the following comment:

Code:
DoCmd.Save ' If BeforeUpdate called us, it should save anyway, no?

I thought the command was superfluous, but it never occurred to me that it would be destructive.

The code also has a number of DoCmd.Close's but without the final parameter.
 
Yeah, get rid of the DoCmd.Save

If you want to save the record you can use either:

DoCmd.RunCommand acCmdSaveRecord

or

If Me.Dirty Then Me.Dirty = False

But if it is on the Before Update event then it isn't necessary anyway.
 
Thank you boblarson!

I do have one question. If I add DoCmd.Save to my y_Click routine above (where I intentionally try to break it), it still doesn't seem to be putting y in the property sheet. Any idea why that would be?

I would love to be able to intentionally reproduce the problem.
 
Well, I'll remove the DoCmd.Save from my production code and keep my fingers crossed!
 

Users who are viewing this thread

Back
Top Bottom