If statement

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

How do I make lcase("A") = ucase("A") return false. I can perform the
oposite in DOS/CMD (if /i A==a returns true, if A==a returns fasle ) but how
is it done in Access?

Thanks,
J.
 
Jason,
from access vba help.
StrComp Function Example
This example uses the StrComp function to return the results of a string
comparison. If the third argument is 1, a textual comparison is performed;
if the third argument is 0 or omitted, a binary comparison is performed.

Dim MyStr1, MyStr2, MyComp
MyStr1 = "ABCD": MyStr2 = "abcd" ' Define variables.
MyComp = StrComp(MyStr1, MyStr2, 1) ' Returns 0.
MyComp = StrComp(MyStr1, MyStr2, 0) ' Returns -1.
MyComp = StrComp(MyStr2, MyStr1) ' Returns 1.


Jeanette Cunningham -- Melbourne Victoria Australia
 
thanks,
I've already created a module using:

Option Compare Binary
Option Explicit

Function

and calling that function. It took a while to find - and didn't see strcomp.
 
Jason,
did you change back to
Option Compare Database
Option Explicit ?

If it still doesn't work, post a copy and paste of your code.


Jeanette Cunningham -- Melbourne Victoria Australia
 
Jason,
in your code put some debug.print statements like this:
Debug.Print "OP: " & OP
Debug.Print "DLookup: " & DLookup("P", "S", "C = """ & SD & """")
If StrComp(OP & "", DLookup("P", "S", "C = """ & SD & """"), 1) ... etc

Run the code by opening the form in normal view and clicking the buttons
etc.

Now do Ctl + G to open the immediate window.
You will see what values access got for OP and DLookup("P", "S", "C = """ &
SD & """")
This will be the clue to why it doesn't work.


Jeanette Cunningham -- Melbourne Victoria Australia
 
Jason,
it would help if you would copy and paste the values into a post.


Jeanette Cunningham -- Melbourne Victoria Australia
 
op: j3678
DLookup: j3678
Jeanette Cunningham said:
Jason,
it would help if you would copy and paste the values into a post.


Jeanette Cunningham -- Melbourne Victoria Australia
 
Jason,
there seems to be some confusion.
op = j3678
DLookup = j3678

These are both the same.
When I test these using strComp I get 0 as the value.
The 0 tells me that the value is the same as the value for DLookup.
Which is what I expect.
It seems to me that access is doing the right thing.

The second test used
op = j3678
DLookup = J3678
This returned a value of 1 which tells us that j3678 is not the same as
J3678.

In other words, the return value of 0 means that both strings are the same.
The return value of 1 means that both strings are not the same.
Does this help?


Jeanette Cunningham -- Melbourne Victoria Australia
 
So returns false (0) when equal and true (not 0) when not equal. Shall try
different approach.
 
I've tried adding = 0 before then. Now it is saying that when J3678 is
entered it is equal and when j3678 is entered that is equal also.
 
Don't know what's going on
I have changed to:
If StrComp(OP & "", DLookup("P", "S", "C = """ & SD & """"), 0) = 0 then
This appears to work
 
Jason,
it's morning here and I am back on the discussion group.
I think it's easier to understand the code when it is written differently.
Here's an example

Dim lngReturnValue as Long

lngReturnValue = StrComp(OP & "", DLookup("P", "S", "C = """ & SD & """"),
0)
Debug.Print lngReturnValue

If Len(lngReturnValue) >0 Then
If lngReturnValue = 0 Then
'code here with action to take
ElseIf lngReturnValue = 1 Then
'code here with other action to take
Else
'code here with other action to take
End If
End If

The 3 parts of the if statement cover the 3 possible return values.

Jeanette Cunningham -- Melbourne Victoria Australia
 
The one line statement works fine. However, I notice that you have also
changed the third number from 1 to 0.
Why is Len(lngReturnValue) required? looks like you are trying to get the
string length from an integer.
 
Jason,

Len(lngReturnValue) is a way of testing whether the result of strComp is
Null.
So in a sense there are 4 possible values from the strComp function.
It makes sense to cover all 4 possibilities in your code in order to cover
for any errors due to unforseen values for OP or the DLookup.


Jeanette Cunningham -- Melbourne Victoria Australia
 
Back
Top