PDA

View Full Version : Run code only if 2 conditions are true



mykal66
09-05-2019, 07:35 AM
Hi

Just trying a more complex database (for me anyway) and needsome advice if anyone can help please?
I need to run a piece of code only if a couple of conditionsapply 1) The Incident Closed box is checked and 2) There is a date in the DateClosed box but completely stuck and tried a few examples from the net butgetting nowhere.
I am just using a msgbox to test where my code would andthis is what I am trying
“ If Closed = TrueThen
Dim udate As Date
udate ="01/01/2000"
IfIncident_Closed.Value > udate Then
MsgBox("TEST")
End If
End If”
I have also attached a screenshot of the part of the form I amtrying to get working. Basically thedays to close would display a number when I run the code (replacing the messagebox I am trying to test with”

Thank you for any advice.
Mykal

OBP
09-05-2019, 07:55 AM
You should be able to use something like the following code (but I have not tested it)

if me.closed = -1 and Not isnull([me.Date Closed]) then msgbox "both conditions met"

You appear to be trying to use Closed instead of me.[Closed date] when comparing the dates.

mykal66
09-05-2019, 08:13 AM
Hi and thank you. I have tried your code and still getting an error messages saying a field in the expression cannot be found, make little sense as only 2 fields are involved

mykal66
09-05-2019, 08:25 AM
Hi again.

Thank you again. I've done this a different way now, the calculation only runs after the date field is updated.

OBP
09-05-2019, 08:44 AM
You have to ensure that the field names are correct, when typing in the VBA Editor if you enter me. the editor will provide a list of all the Controls, including the fields that can be used