PDA

Click to See Complete Forum and Search --> : Null Value


casox
Mar 21st, 2000, 10:38 PM
What would create an "Invalid use of Null" error? Seemingly the particular field in question has the same settings as the rest (access 2000), required no, allow zero length yes, indexed no. Also, it is not a primary key. I don't want to check for a null value or some type of work around, to me, it seems this should not happen. Is it a bug? ie. what causes this? Anyone?

Thanks,

casox

[Edited by casox on 03-22-2000 at 11:43 AM]

Glenn
Mar 21st, 2000, 11:40 PM
If the field is not required and is not filled in then it will be NULL.

Handling the null should not be considered a workaround, you should consider it good database programming :)

[Edited by Glenn on 03-22-2000 at 12:41 PM]

casox
Mar 22nd, 2000, 12:36 AM
I have 42 fields, 39 of which are currently not filled and not required, only the one in question gives me an Invalid use of Null, the others are fine. I understand that it is a null value, however, my question is why would the use of one particular null value be invalid, while others which are seemingly being handled the same way are without error? Ponimaesh? Verstace?

casox

[Edited by casox on 03-22-2000 at 01:43 PM]

pardede
Mar 23rd, 2000, 05:24 AM
sometimes its a matter of which datatype the field has, or whether any function is used on the value, or if any comparison was done... posting your code might clarify the situation?

[Edited by pardede on 03-23-2000 at 06:26 PM]

casox
Mar 23rd, 2000, 08:43 PM
Here's a sample of my code. The table is in Access 2000. All of the fields are of type text, all of their attributes are identical, on the surface that is. There are no functions applied to any of them and no comparisons have been done with the one in question. Can anyone help me dig further? Thanks.

casox

Private Sub display()

'Refreshes screen if records exist

If InventoryTB.RecordCount > 0 Then

'Checks for beginning of file

If InventoryTB.EOF Then

InventoryTB.MoveLast
MsgBox ("You've reached the last record in the file."), vbInformation

End If

'Checks for end of file

If InventoryTB.BOF Then

InventoryTB.MoveFirst
MsgBox ("You've reached the first record in the file."), vbInformation

End If

txtLocation.Text = InventoryTB!Location
txtAssignedTo.Text = InventoryTB!EmployeeName ' Gives me Invalid use of null
cmbDescrip.Text = InventoryTB!Description
cmbModel.Text = InventoryTB!ModelNum
txtModelSerialNum.Text = InventoryTB!ModelSerialNum
txtModelAssetNum.Text = InventoryTB!ModelAssetNum
cmbEthernetLan.Text = InventoryTB!EthernetLan
cmbMonitor.Text = InventoryTB!Monitor
txtMonitorSerialNum.Text = InventoryTB!MonitorSerialNum
txtMonitorAssetNum.Text = InventoryTB!MonitorAssetNum
txtNetworkName.Text = InventoryTB!NetworkName
txtIPAddress.Text = InventoryTB!IPAddress
cmbAcquisition = InventoryTB!Acquisition
cmbCDRom.Text = InventoryTB!CDRom
cmbZip.Text = InventoryTB!ZipDrive
txtZipSerialNum.Text = InventoryTB!ZipSerialNum
txtZipAssetNum.Text = InventoryTB!ZipAssetNum
cmbTape.Text = InventoryTB!TapeDrive
txtTapeSerialNum.Text = InventoryTB!TapeSerialNum
txtTapeAssetNum.Text = InventoryTB!TapeAssetNum
cmbJazz.Text = InventoryTB!JazzDrive
txtJazzSerialNum.Text = InventoryTB!JazzSerialNum
txtJazzAssetNum.Text = InventoryTB!JazzAssetNum
cmbKeyboard.Text = InventoryTB!Keyboard
txtRAM.Text = InventoryTB!RAM
txtHardDrive.Text = InventoryTB!HardDrive
cmbOPSystem.Text = InventoryTB!OperatingSystem
cmbMouse.Text = InventoryTB!Mouse

cmdAddRecord.Enabled = True
cmdDeleteRecord.Enabled = True
cmdGotoRecord.Enabled = True
cmdUpdateRecord.Enabled = True
cmdSearchRecords.Enabled = True
cmdQuit.Enabled = True
cmdSaveRecord.Enabled = False
cmdCancel.Enabled = False

End If


End Sub

JHausmann
Mar 24th, 2000, 12:34 AM
do this:

txtAssignedTo.Text = InventoryTB!EmployeeName & ""


You won't get invalid use of null if you use this as a standard.

pardede
Mar 24th, 2000, 02:23 AM
I agree with JHaussman, that's really the simplest way to prevent the null value error.

Still it intrigues/puzzles me as to why this happens. Having seen your code I don't think the problem is in the db-field cause what the code was trying to do is setting the text of a control to Null, and it refuses, quiet logical really. But why is there no problem with the other fields? Are their values never Null, in other words they contain nullstring ("") when empty? Or is there something special about the control "txtAssignedTo"? Maybe you should look at that.

casox
Mar 28th, 2000, 12:35 AM
Thanks for the help. Yes, it intrigues me also. There really is nothing special about the particular field. I don't know?!?!?!