VBA three criteria messagebox

ECEK

Registered User.
Local time
Today, 21:36
Joined
Dec 19, 2012
Messages
717
I am closing my form and wish to validate the entries.

What I want to do is check the fields for validated data.

In order to flag a message: The following must be met
1. That the record is saying "Completed"
AND
2. One date is after another date
AND
3. There is no data in the "reason field"

I tried to do the calculation within my vba but instead I have done this separately and saved the result in an unbound field (datediffs)

Code:
Private Sub Command70_Click()
Me.Refresh
Me.Requery
Me.datediffs = Me.rep_rb - Me.drc


If Me.rec_type = "Completed" And Me.datediffs < 0 And IsNull(cnm_reason) Then


MsgBox "Please give a reason why this report is late"

Exit Sub

Guess what ? it doesnt work !!!

I have tried just the
Code:
If Me.datediffs < 0 Then
and this works.

I'm just struggling to get all three rules to evaluate. It doesnt crash, it just closes my form.

Thanks peoples !!
 
That eliminates one evaluation. Now test the other 2. I would do this by printing out the actual values in each variable being tested so I could see their values with my own eyes.
 
Hi ECEK,

I can see a couple of things:

First there is block if without End If.

Second, assuming "cnm_reason" is a field, you should include "Me". So the total code would be:

Code:
Private Sub Command70_Click()
Me.Refresh
Me.Requery
Me.datediffs = Me.rep_rb - Me.drc


If Me.rec_type = "Completed" And Me.datediffs < 0 And IsNull(Me.cnm_reason) Then


MsgBox "Please give a reason why this report is late"

End If

Exit Sub

Hope that helps.
 
In my response yesterday I mistook "Exit Sub" for "End Sub" - sorry.

So End If should come after Exit Sub of course. And it may, because I now see you haven't included code beyond Exit Sub!

The point about "Me." still applies though.
 

Users who are viewing this thread

Back
Top Bottom