A site for solving at least some of your technical problems...
A site for solving at least some of your technical problems...
A few days ago, I made many updates in one of the MS-Access forms I'm working on.
Then, when I tried to open the form I'd get this error...
The Expression On Load you entered as the event property setting produced the following error: User-defined type not defined
This doesn't mean anything to me since I did not define any type... Removing the Form_Load function (commenting it out) made that very error go away, however, since that's the sub-form of another form, it still generates errors when the main form is trying to initialize the sub-form.
Note that it mentions OnLoad(). Commenting out that function doesn't remove the error so the problem is not that function.
Now the error is:
Run-time error '40036':
Method 'Form' of object '_SubForm' failed
So I still have a problem...
Thinking about it, I thought that would come from a function I changed, but I could not remember specifically which one that would be. I changed many functions all at once...
So to find it, I finally cut out all the functions from the macro file and saved them in a .txt file with NotePad. Then I copied those back, one by one, and tried to open the form each time. Worked great up until I pasted the offensive function.
The fact is the list of parameters is what causes this problem (at least in this case, but it sounds that in many cases, that's the problem!)
The function that broke my MS-Access application was:
Private Function Foo(Code As Code)
Little mistake... Code is a Long! So, look at the error: "User-defined type not defined", very cryptic if you ask me since I never intended to create a "user-defined type," but that was indeed the problem.
So, I changed my function to this and it works like a charm again:
Private Function Foo(Code As Long)
Before finding the solution presented here, I read many posts on forums from people who would explain to others why they were getting this error.
The fact is that 99% of the time those answers were wrong.
Examples:
Recent Posts on The Linux Page:
Re: The Expression On Load you entered as the event property ...
He seems to be correct, I had this issue and it caused serious delays and backtracking. I think the problem is fully identified based on the following:
Access apparently cannot recognize any event procedures if one of them is out of whack. So in my case, I had a mouse move event I needed to implement over an image. When I clicked the mousemove event, then selected code, the function it gave me looked like this:
Private Sub Device_Type_Info_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
end sub
I did not understand why all those arguments were added, I'm not using them... so I stupidly deleted all the arguments. Alas, after that not a single event was recognized and this error popped up every time any event on this form occurred, none would run.... I finally back tracked and either reapplied the arguments or just deleted that event function and started over on it... lesson learnt: don't mess with the event sub declaration statements.