vba code disappears

Eljefegeneo

Still trying to learn
Local time
Yesterday, 22:12
Joined
Jan 10, 2011
Messages
902
I have come up with a problem that I cannot figure out. I had some vba code behind a command button that would make sure the user filled out all the required fields when clicking the "close" button. All of a sudden the form wouldn't close and I got a frantic call from a user. So I looked at my sample DB and indeed the button wouldn't work. After fiddling with it for several minutes I opened the properties for the button, selected the "Code builder" and voila! the code was there. All I had to do was click save and all was well.

I did not change the name of the button prior to this happening, that is from Command1234 to cmdcClose.

I just want to make sure that I not doing something that I shouldn't that might cause this to happen? I do backup and Compact and Repair regularly as this Db is an ongoing development. Anyone have any ideas? Thanks.
 
Hi,
You have apparently never lost the code, it has just not bin executed...
I could think of a reason for that: Is it possible the on Close event in the properties had no reference in the Form_Close event procedure? in that case, clicking on "Code builder" option checks for this procedure, creates one if dose not exist, and creates s reference to it.

ATB
 
If you read the code it may still be referring to Command1234 instead of CmdcClose.

Marian may also be correct.

So both may need attention.
 
Thank you both for your replies. No, the command button named cmdClose was never named anything else. And the code was there before the discovery yesterday. It just disappeared and then reappeared when I used the code builder again. I have had this happen before but I thought it was just something I had done wrong. But this time I knew I had the code in the right place.

Another Access mystery?
 
you may have accidentally deleted [Event Procedure] from the button onclick event - the code would remain in the vba but never be triggered. Selecting it again would solve the problem
 
Another Access mystery?
Corruption?... :eek:
This is what has append to me a short while ago, http://www.access-programmers.co.uk/forums/showthread.php?t=276786
I recreated the file, and rewritten all code!
Here is an other great link for dealing with Corruption: http://allenbrowne.com/ser-47.html

But it really seems to me like some reference issue: if the control is there and the code is there, all you need is a reference from the control to the Code. You could have accidentally deleted [Event Procedure] from the properties.

ATB!
 
Something that I had happen to me recently is:

I had written the code for a database that built its tables based off of the data within hundreds of thousands of engineering data text files. It had to create its tables and fields on runtime.

The result of this was a database with 1.34 million records. After a few days I noticed the database literally starting to implode. Little things here and there disappearing until eventually I lost all my code and data... depressing!!!! lmao
 
The symptoms make it seem as though some sort of global text-edit might have occurred that changed the name of the event entry point, or something swept through the controls and modified the event entry point in some way. But if it then found the code again without editing, the problem is more confusing because the name has to be the same for the code to show up as you describe. It smells of someone doing an edit and then realizing that it was excessive in some way, so that person un-did the edit.

Even a Compact/Repair does not ordinarily muck about with entry points. If you changed the name of the form, I would have thought that more than one command button would be broken - though again that doesn't usually happen at all.

Your stated "fix" only confuses the issue. If you simply double-click the event slot and suddenly the code appears, that isn't compiling the code. (That takes another action.) That is merely refreshing the contents of the event slot in the properties.

Now, if the button was not an Access button but one of the extended ActiveX buttons and you suddenly had a reference problem, that might do it. Otherwise, I don't see this one clearly.
 
My thanks to everyone who replied. After thinking about it today, I realized that since I am constantly updating the DB and the form codes, sometimes I may do it too fast and not thoroughly check everything out. But in this case all I did was change the format of the button. Could this have occurred when I changed the format of the button and forgot to "save" the update and thus hid the code?

I am the only person who makes any changes on the forms, especially the vba codes.

I now realize that I cannot be negligent in making a backup of the front end especially when changing anything at all.

Again, thanks to everyone who replied.
 
I still believe that there is something wrong with the code.

Can you post a copy of the DB. If not then the latest code plus an earlier version before the major code.

We should be able to work it out from there.

I now realize that I cannot be negligent in making a backup of the front end especially when changing anything at all.

This is a very good lesson. Personally I could make 20 - 40 copies in a day. However I wrote a simple database that makes creating a back up quick and easy.
 
I have had loads of experiences where a form has corrupted, giving strange messages, making the form unusable, and occasionally deleting the vba. I keep a healthy version history of all my databases to be able to restore any vba from time to time. It does seem random to me.

In terms of the dbs, though, I guess it just needs one pointer to get corrupted, to end up with orphan vba code. I expect that is what is happening inside the database.
 
I have had loads of experiences where a form has corrupted, giving strange messages, making the form unusable, and occasionally deleting the vba. I keep a healthy version history of all my databases to be able to restore any vba from time to time. It does seem random to me.

In terms of the dbs, though, I guess it just needs one pointer to get corrupted, to end up with orphan vba code. I expect that is what is happening inside the database.

Dave

Would you not think that the problem can be solved. After all we have not proven that it is corrupt.

He has not complained about the normal errors that you would get with a corrupt DB. No report of corrupt files in tables. No reported error with a compile. We have not done a decompile.

Maybe it is just me but I believe it is an EBCC error.
 
I meant that forms can get corrupted.

eg, (I think these sort of things) I recall occasionally having trouble adding controls to continuous forms, and then deleting the label. Sometimes the form will not reopen after closing. Sometimes I get out of memory errors. When I close and reopen, the form is just unusable.

I have also discovered empty code modules from time to time.

That was all I was observing.

----
Another thing I do from time to time is use vba code to add code to existing code modules - eg, where I want an extra line adding to every form's Open event. By trial and error, I only do this for 50 objects at a time.
 
Sometimes the form will not reopen after closing. Sometimes I get out of memory errors. When I close and reopen, the form is just unusable.

This looks to me like the Form has been imported/exported.

Other than that I used to have the same problem but it has not occurred since I stoped importing. This was many years ago that I had the problems.
 

Users who are viewing this thread

Back
Top Bottom