Question "Invalid use of Null" error

catchthewind

New member
Local time
Today, 17:02
Joined
Aug 6, 2008
Messages
2
I'm an access newbie, and have found this forum very helpful so far.

In my project, I have a form with a toggle button that says "add a new record" that should open the form "ECPMaster" so I can enter the new data when I click on it. My problem is that I'm getting an "Invalid use of null" error message. After the message I click OK and the form opens and seems to be working correctly. I can't figure out why I'm getting the error message though. There is no error number shown or debug button to show me the code that is causing the error. I have another toggle button, "edit record", that opens the same form and allows me to edit records and I'm not getting the "Invalid use of Null" error message then.

Does anyone know how I can fix this error or how to locate what the cause of the error is? Here's my code for the "add" and "edit" toggle forms:

Private Sub Toggle2_Click() 'Open ECPMaster form to create new ECN
DoCmd.Echo False
DoCmd.OpenForm "ECPMaster", acNormal, , , acFormAdd
''Disables navigation buttons
Form_ECPMaster.FirstRecord.Visible = False
Form_ECPMaster.LastRecord.Visible = False
Form_ECPMaster.PreviousRecord.Visible = False
Form_ECPMaster.NextRecord.Visible = False
DoCmd.Maximize
DoCmd.Echo True
Toggle2 = False
End Sub


Private Sub Toggle3_Click() 'Opens ECPMaster Form in Edit mode
DoCmd.Echo False
DoCmd.OpenForm "ECPMaster", , , , acFormEdit
Form_ECPMaster.AllowAdditions = False
DoCmd.Maximize
DoCmd.Echo True
Toggle3 = False
End Sub
 
Simple Software Solutions

Invariably Invalid use of Null normally refers to a control that was expecting a value but is Blank (Null). Lets say you have some sort of calculation on your form (A+B=C) if A has a value but B = null You cannot add A and Null together. what you need to do is when you get the error you usually get a End - Degub option on the message box, click Debug. This will take you to the line that is causing the problem. Hover your mouse over the line and see which element is returning the Null value.

CodeMaster::cool:
 
Thanks for your help. I had a function in the OnCurrent event that referenced a data field that had not been filled in yet when a new record was created, giving the null error.

For future reference though, the error message box did not have the usual End-Debug options, only an OK button, so is there a way to identify which line of code is causing the problem without the Debug button?
 
Click my siggy for details on how to debug.
 

Users who are viewing this thread

Back
Top Bottom