"Invalid Null" error in DoEvents statement in MsAccess

I have a strange situation in Access. The generally invalid use of a Null error is a fairly simple thing - assigning a null value to a string variable or some such. But I am getting an error at a place where it seems to me that this should not be happening. Here's a snippet of code:

bch = Form_Akces.txtMaxCisla.BackColor
If Err <> 0 Then Stop
Form_Akces.txtMaxCisla.BackColor = vbYellow
If Err <> 0 Then Stop
DoEvents
If Err <> 0 Then Stop ' This is where I get the error
With qdf_GPsp

      

What happens is that I only get this error occasionally, usually only the first time I run the code after a while. If I close the database and immediately open it again, I usually don't get the error. This turned me on for quite some time, so I included all these "If Err <> 0 Then Stop" statements trying to track down where this is happening. It's a live system and users know to just restart the app, but it's a massive PIA and awkward to load.

Can anyone think of something to try? I'm not really a fan of Access, but it's far beyond what I've ever encountered. Why the DoEvents instruction should generate such an error is beyond my scope, especially since I do nothing even in the previous instructions, which should generate such an error that it can somehow be "saved" until the processor will get the option to throw an error, If I choose DoEvents, I just get the same error a little further down the line. txtMaxCisla is an unbound text field in Form_Akces from which the procedure containing this code is called. This is only at startup - once everything is uploaded and running, it will never happen again. And this only happens from time to time - there is no pattern that I could find.

This went on for months, thanks to numerous compilations, decompilation, recompilation, compression and repair of loops without noticeable changes, except that sometimes it happens in other places, again for no reason I can see.

  • Update *

No luck - it still crashes, and for absolutely NO reason I can see. Here is the code now:

Public Sub ReloadMaxNumbers(tmc As TextBox)
Dim rst As DAO.Recordset, x$, xb$, xe$, bch&
On Error GoTo 0
If Err <> 0 Then Stop
DoEvents
If Err <> 0 Then Stop
...

      

The code stops in the SECOND test after DoEvents with the same "Invalid Null" error. I understand that this code is completely stuck, but this is the result of tracing back trying to find the root of the error. Without this, he gets lost on the road somewhere with the same error. At the moment, I can't think of anything else to even try.

+3


source to share


1 answer


I am puzzled Form_Akces

about your code. If I create a form named Akces

, the form's code module is called Form_Akces

. But you said "on the Form_Akces". So I am confused if the Form_Akces

name of the form or module is the code of the form. Perhaps Access is confusing too.

Anyway, since you said the code is in the form's code module, I suggest you replace Me

withForm_Akces

Edit . I misunderstood your situation. This code that you showed us is actually a procedure in another code module, not a form code module. In this case, I would do something like this for an external procedure DoSomething

:

Public Sub DoSomething(ByRef frm As Form)
    bch = frm.txtMaxCisla.BackColor
    frm.txtMaxCisla.BackColor = vbYellow
    DoEvents
    ' whatever else you need
End Sub

      

Then in the form code module where you call DoSomething:



DoSomething Me

      

And if DoSomething

only works with one control at a time, you can simply pass a reference to that control.

Public Sub DoSomething(ByRef ctl As Control)

      

This approach will allow reuse DoSomething

for other forms without any changes, because the target form name is not "hard-wired" to the procedure. Also, it won't break if you rename the form Akces

. In the second option, it will also take into account changes in the name of the control.

+1


source







All Articles