Yes, I believe that a textbox automatically trims trailing spaces. The problem with using a space as a critical piece of data is that it is invisible. It looks exactly like a Null in a textbox. Whatever a single space indicates in your system, I would use some other means to signify its presence.
how is your table/field set up. (allow zls/required)
you probably do not need an actual space. You can have a zero length string. a zero length string is not considered the same as a null by access
eg
https://599cd.com/tips/access/null-zls/
Space is not elegant at all.I'm using a "." at the moment but a space would be more elegant
I have Allow zero length set to null.If I put a space in the field it seems to 'disappear'. The table is used in a combo box and it does look like there is a blank/space line in there. But if it is selected it's failing a piece of code -
If IsNull(Me.Organisation) Or Me.Organisation = "" Then
MsgBox "You must enter an Organisation or use the Cancel option to exit the form!", vbOKOnly
I'm not sure why Me.Organisation = "" is in there in the 1st place but I was presuming that putting a space in the field would make this statement FALSE.
I'll take a look at the link when I get 5 mins...
If IsNull(Me.Organisation) Or Me.Organisation = "" Then
MsgBox "You must enter an Organisation or use the Cancel option to exit the form!", vbOKOnly
using the nz function, as
If nz(Me.Organisation,"") = "" Then
etc
first bit in bold. what do you mean, allow zero length set to NULL. It's either set to yes or no.
if your field is set to "required = true", then null is not allowed
if allow ZLS is true, then you can still have a value of "", otherwise you are forced to enter a specific value.
if you want to force an organisation to be entered simply set "required=true" and "allow ZLS=false". However if you have blanks at the moment, you won't be able to set this rule, as it will be broken by existing data.
you can combine this more simply
If IsNull(Me.Organisation) Or Me.Organisation = "" Then
MsgBox "You must enter an Organisation or use the Cancel option to exit the form!", vbOKOnly
using the nz function, as
If nz(Me.Organisation,"") = "" Then
etc
if you are just trying to prevent nulls and want to allow a "blank" value, simply do this in the forms beforeupdate event
organisation = nz(organisation,"")
now you won't have any nulls at all, but you will have blanks. So your field must be set to "required=true" (to prevent the null) and "allow zls=true"
I don't understand the point about the combo box really. That's just a natural result of your "business requirements".
I hope all this makes sense
why force your users to put nonsense into a field that should just hold NOTHING aka NULL?
So why not force them to put something a bit more 'meaningful' like 'N/A' or 'None'If I allow them NOT to put anything in then they won't. I want to force them to put nothing in!!!
See above!!!
If I allow them NOT to put anything in then they won't. I want to force them to put nothing in!!!
The only way I can see in doing this is to make it a compulsory field but allow them top select blank. If they have to select something they will select the right thing. If it's not compulsory then they won't/
Playing devils advocate
So why not force them to put something a bit more 'meaningful' like 'N/A' or 'None'
bit in bold. That just sounds crazy. you want to force them to indicate the selection really is blank?
so maybe instead of free text, give them a combo box, with one of the options being "no item selected"
Thinking out loud here...
Why not just put a message in the On_Exit or After_Update of the Text Box. Something like...
*Did you mean to leave this empty?*
If I knew I was going to get that message every time I was too lazy to fill in a field believe me if I knew the data it wanted I would enter it.
Side note, if this is a Combo Box you can set the first value as Blank as long as it's not the PK and then your Users can select something. You could then use validation to insure they selected something. And that would be easy enough to work with for reports.