Len(string) and strComp() not working for me

Shaftsbury

New member
Local time
Today, 07:41
Joined
Feb 10, 2009
Messages
7
[SOLVED] Len(string) and strComp() not working for me

I'm trying to set up a form so that certain controls are "enabled" when the form is still being worked on = "Open" versus one that is "Closed".

I am using conditional statements to test the text in the "Status" field.

I can't seem to get a match when my variable (strStatus) is compared with "Open" or "Closed" eg. If strStatus = "Open" Then...

So I tried using strComp(strStatus,"Open",vbTextCompare) but it keeps returning 1 no matter what the text in the field is.

As a last resort I tried to get the length of the strings to compare them that way lngStatus = Len(strStatus) but strangely it is giving me the length of the field not the length of the string. eg. the field is nchar(10) and Len(strStatus) = 10 on every record.


We are using Access 2013 with Microsoft SQL Server 2012, I never had this problem when we were using Access as the back end.


I don't get it?

 
Last edited:
It looks like the text was padded out to 10 characters so instead of "Open" the text was actually "Open " I changed the format of the field to nvchar and removed the extra padding, hopefully that will fix it when new data is put in. :)
 
Use the Trim() function to remove whitespace from the beginning and end of the value.
 

Users who are viewing this thread

Back
Top Bottom