Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using StrComp

Status
Not open for further replies.

cneill

Instructor
Mar 18, 2003
210
GB
Hi,

Dim Add1 As String
Dim Add2 As String
Dim TestComp As Integer

Add1 = Me.Address
Add2 = Me!frmDeliveryAddressSubFrm.Form![Address]

TestComp = StrComp(Add2, Add1)

If TestComp = -1 Then
MsgBox "The Main Address, does not match the Delivery Address, Please correct this Information", vbOKOnly, "Just to let you know"
Exit Sub
End If

The above code works find for fields with text, sometimes one of the fields (could be either) is empty
How do I add code to test for a Null Value or nothing?

Many Thank

Neill
 
something like this ?
Code:
If Trim(Me!Address & "") <> "" And Trim(Me!frmDeliveryAddressSubFrm.Form!Address & "") <> "" Then
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
this is not giving me the results I need, may be I going about this in the wrong way. What I would like to do when the user closes the form

is to campare the Me!Address (main Form) to the Me!frmDeliveryAddressSubFrm.Form!Address (Sub Form) the correct result is that they should be the same
either
Result 1 = the same text so okay to continue to close form
Result 2 = both fields are empty so okay to continue to close form
Result 3 = if both fields are Null so okay to continue to close form

if the above is not true i.e. the text is different or one field is null and the other one has text then the msgbox should be displayed and the form will not close until the user has corrected the problem.

Thanks

Neill
 
So, simply replace this:
Add1 = Me.Address
Add2 = Me!frmDeliveryAddressSubFrm.Form![Address]
with this:
Add1 = Trim(Me!Address & "")
Add2 = Trim(Me!frmDeliveryAddressSubFrm.Form!Address & "")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You might want to check for:
Code:
TestComp <> 0
As -1 will only be returned if string1 is less than string2, if string1 is greater than string2 then it will return 1.

Hope this helps

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top