Here is the situation: There's a SQL Server database with a Microsoft Access front end. There is a table in the SQL Server database with a column called PackID which is defined as VARCHAR(6) NOT NULL (it has to be NOT NULL because it's part of a composite primary key for this table). Empty strings are legitimate in the PackID column. In fact, they occur quite often. When the user enters data in the UI for this table, and tabs through the PackID field, an error message appears: "Cannot insert the value NULL into column 'PackID'; column does not allow nulls. INSERT fails."
Things that have been tried that do not work:
calling the following VBA code when user moves off row in UI (Lost Focus event)
If IsNull(PackID.Value) Then
PackID.Value = ""
End If
Does anyone know how to force an empty string in Access so it's interpreted as an empty string for SQL Server and not a NULL?
Setting the Default Value in the text box Properties for PackID in Access to this
=" "
worked. The space between the double quotes is very important. Leaving the space out causes the insert to fail. In SQL Server LEN(PackID) returns 0. For instance:
SELECT LEN(''), LEN(' ');
both return 0. It appears as though SQL Server treats both of these as empty strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With