Help with IF Statement

jason_kelly

Board Regular
Joined
Jul 8, 2010
Messages
50
Hi There,

I have the following code below, that will basically execute a function based on wether or not if there are specific fields on a form which are filled out.

The problem is this, when the fields (h3, h9 and h5) are all filed in, I have 2 message boxes that are appearing and popping up:

"V4_SEARCHBYASSIGNTO" and
"V4_SEARCHBYASSIGNTO_WTYPE"

The only message box that should be popping up is:
"V4_SEARCHBYASSIGNTO_WTYPE"

Any help with this is greatly appreciated.

Cheers,

Jay

Code:
[LEFT]Private Sub btn_search_Click()
'V4_SEARCHBYFILE
'V4_SEARCHBYSUB
'V4_SEARCHBYASSIGNTO
'V4_SEARCHBYASSIGNTO_WTYPE
 
If frmIMTS.h1.Value <> "" Then
MsgBox "V4_SEARCHBYFILE"
End If
 
If frmIMTS.h12.Value <> "" Then
MsgBox "V4_SEARCHBYSUB"
End If
 
If frmIMTS.h5.Value <> "" And frmIMTS.h9.Value <> "" Then
MsgBox "V4_SEARCHBYASSIGNTO"
End If
 
If frmIMTS.h3.Value <> "" And frmIMTS.h9.Value <> "" And frmIMTS.h5.Value <> "" Then
MsgBox "V4_SEARCHBYASSIGNTO_WTYPE"
End If
 
End Sub[/LEFT]
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If H3, H9 and H5 are filled in, then aren't both conditions met?

Code:
If frmIMTS.h5.Value <> "" And frmIMTS.h9.Value <> "" Then
MsgBox "V4_SEARCHBYASSIGNTO"
End If
 
If frmIMTS.h3.Value <> "" And frmIMTS.h9.Value <> "" And frmIMTS.h5.Value <> "" Then
MsgBox "V4_SEARCHBYASSIGNTO_WTYPE"
End If

Perhaps you want to modify the "V4_SEARCHBYASSIGNTO" msgbox to:

Code:
If frmIMTS.h5.Value <> "" And frmIMTS.h9.Value <> "" and frmIMTS.h3.Value = "" Then
MsgBox "V4_SEARCHBYASSIGNTO"
End If

So alert only if H5 and H9 are filled out, but not H3? A Select Case statement might work real well here too.
 
Upvote 0
Thanks bs0d,

The way this was setup to work was:

V4_SEARCHBYASSIGNTO is triggered by filling only 2 fields and the

V4_SEARCHBYASSIGNTO_WTYPE is triggered by filling out the 3 fields.

I can't seem to get excel to differentiate between the 2.

Jay.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,752
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top