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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple IF Statement (or should be!)

Status
Not open for further replies.

ghayman73

Technical User
Jul 3, 2002
55
0
0
FR
I thought this would be easy but I Just dont get whats wrong.

I have a form wich has three text boxes
keyword
SID
searchphrase

all i want to do is when i load the form i want to check if there is a value is searchphrase ifnot then the value will be same as keyword.

Ive tried this and a few things like this but i just dont know enough to see the errors.

Private Sub SID_BeforeUpdate(Cancel As Integer)
If Me.searchphrase = "" Then
Me.SID = Me.keyword
End If
End Sub

Any help would be appreciated

Grant
 
Try

If IsNull(Me.searchphrase) Then

If the field is truly empty...it is probably null...

****************************
Computers are possibly the most un-intelligent things ever invented, yet we let them control the world. Possibly a reflection of our own stupidity.

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Private Sub SID_BeforeUpdate(Cancel As Integer)
If Me.searchphrase = "" Then

try
If isnull(Me.searchphrase) Then

Me.SID = Me.keyword
End If
End Sub
RGB
 
If nothing is entered into Searchphrase yet, it may be Null. Try If Me.searchphrase = "" Or IsNull Then and see if that works

GTLoco
 
still not getting any values in SID

Is this part correct

Private Sub SID_BeforeUpdate(Cancel As Integer)

its a text field so the word Integer confuses me unless its saying if its a number cancel the action ??

Grant
 
The (Cancel as Integer) means that Cancel is a parameter passed into the BeforeUpdate event, and the variable Cancel is of type integer. You can set the value of Cancel to True (-1) to cancel the Update.

With respect to your assignemnt issue, Have you tried the following:

Private Sub SID_BeforeUpdate(Cancel As Integer)

If (Nz(Me.searchphrase, "") = "") Then
Me.SID = Me.keyword
End If

End Sub


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Grant,
ont thing to keep in mind, Before update requires you to 'Enter' the textbox in order to trigger the code check.
Try
Private Sub Form_Open(Cancel As Integer)
If isnull(Me.searchphrase) or Me.searchphrase = "" Then Me.SID = Me.keyword
end sub

Private Sub Form_Load()
If isnull(Me.searchphrase) or Me.searchphrase = "" Then Me.SID = Me.keyword
end sub

RGB
 
Thanks for all your replys

RGB that seems to work great, "BUT" theres always a but isn't there.
It only works on new records I insert is there a way of getting it to run on previously entered records.

Does this mean that previously entered records dont have a truly null value or is there something else im missing.

Grant
 
Grant,
Any records that are previously in a table will not be updated by opening the form. If this is a one time update, create a query to update previous records. It it is a continuing situation, still create the query, but run it when the form opens or put and 'Update Button' on the form.

Caution:
Be sure to watch your criteria as to not overwrite previously updated records with dis-information.
RGB
 
You probably don't need this, but I've found it helpful in the past.

I've had trouble with the &quot;If value = &quot;&quot; or isnull(value) = true then...&quot; statement. The way I've gotten around it is to not use value = &quot;&quot;, but instead use len(value) < 1. I have found this to handle empty fields a bit better.

Jay
 
I use the following function

Public Function isblank(ByVal v As Variant) As Integer

If IsNull(v) Or IsEmpty(v) Then
isblank = True
ElseIf v = &quot;&quot; Then
isblank = True
Else
isblank = False
End If

End Function
 
Grant,

Another solution is to put the if statement into the control source property of the(a) textbox.
Code:
=IIf(Nz([searchphrase],&quot;&quot;)=&quot;&quot;,[keyword],[searchphrase])
I don't know how it will function in your situation, but may be worth a try

Shane
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top