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

If statement not working

Status
Not open for further replies.

mdmarney

IS-IT--Management
Jan 16, 2003
68
0
0
US
The following code always comes out TRUE.

If Me!Parish_Group_Arrival.Value Then
DoCmd.RunSQL "UPDATE tbl_attendants SET Arrival_Verification = TRUE WHERE Parish_Group_Arrival = TRUE AND Parish_Group_ID = Forms!frm_Check_In_Attendants_by_Group!frm_Check_In_Attendants_by_Group_Subform.Form!Parish_Group_ID"
Else
DoCmd.RunSQL "UPDATE tbl_attendants SET Arrival_Verification = FALSE WHERE Parish_Group_Arrival = TRUE AND Parish_Group_ID = Forms!frm_Check_In_Attendants_by_Group!frm_Check_In_Attendants_by_Group_Subform.Form!Parish_Group_ID"
End If

Any thoughts? *************
M. MARNEY
 
Just add the value you are testing for.
If Me!Parish_Group_Arrival = -1 Then
Do this
Else
Do that
End If

Right now all it's testing for is if there is a value and that always tests true.

Paul
 
Paul,
That did not work. I have tried TRUE as well
here is the code...

If Me!Parish_Group_Arrival = -1 Then
DoCmd.RunSQL "String Here (Works)"
Else
DoCmd.RunSQL "String Here (Works)"
End If

Ideas? *************
M. MARNEY
 
Where are you running this code. Is it in an event on a form? Double check the Name property of the Control Parish_Group_Arrival. It may be bound to Parish_Group_Arrival but that doesn't meand that that is the name of the Control.

Paul
 
I am running this code on the after_update event of the check box which is named Parish_Group_Arrival and is bound to the same name. *************
M. MARNEY
 
Don't know. I just ran some code to double check and it works the way you would expect. What is the Triple State property for the check box set to. I would assume "No". It could make a difference but no matter what if you select and deselect the checkbox, it should at some point evaluate to False.

Paul
 
See, that's the problem. It never evaluates to false! Is it the After_Update event that is the problem? I tried the on_click, but that did not work either. (The triple property is false.) *************
M. MARNEY
 
There shouldn't be a problem with AfterUpdate event. I've tried (and it works):

[ttPrivate Sub Parish_Group_Arrival_AfterUpdate()
If Me.Parish_Group_Arrival.Value Then
MsgBox "Checked!"
Else
MsgBox "Unchecked!"
End If
End Sub[/tt]

Is the SQL string really right? You have Parish_Group_Arrival = TRUE setted in both cases...
 
mdmarney:

You are testing whether or not there is a value in Parish_Group_Arrival, not what the value is. If the field in the underlying table is a Yes/No field, then there is always a value: and empty checkbox equates to FALSE.

I believe you need to write the IF statement as follows:

If Me!Parish_Group_Arrival.Value = TRUE Then


Also, unless I missed something, the WHERE clauses of both strings are identical, so I don't think the update can function properly.

Hope this helps,

Vic
 
Vic,
I am currently running the code you suggest. It still does nto work properly. I used the debug to check the numbers and conditions are being met, but the update is not happening under the right conditions.
Also, there is a difference in the update strings. Notice: Arrival_Verification = FALSE and Arrival_Verification = TRUE are the differences. *************
M. MARNEY
 
Hi md,

<AfterUpdate> will only fire if you move to another record or UPDATE the record another way i.e. SAVE IT).

Try this:
rename the chkbox to chkParish_Group_Arrival (all form objects should be named with a suffix for this very reason).

Then use:

'msgbox Me!chkParish_Group_Arrival'

in the <On Click> event of the checkbox. (Comment out all other code).

Click the checkbox several times - whats the msgbox result?
Does it change dependant on the value of the checkbox?

Bet it does.

I think that what you THINK should happen with your 'RunSQL' command isn't happening, because your logic is wrong.

Regards,

Darrylle &quot;Never argue with an idiot, he'll bring you down to his level - then beat you with experience.&quot; darrylles@totalise.co.uk
 
Hi,

Vic, 'msgbox me!object' and 'msgbox me!object.value' is an identical statement.

Both refer to the object's contents.

What may be happening is that the object name is the same as the underlying bound fieldname - and Access is possibly refering to the 'boolean' value of whether or not the underlying field is null or not.

Regards,

Darrylle





&quot;Never argue with an idiot, he'll bring you down to his level - then beat you with experience.&quot; darrylles@totalise.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top