Consulting

Results 1 to 5 of 5

Thread: Run code only if 2 conditions are true

  1. #1
    VBAX Contributor
    Joined
    Jul 2011
    Location
    Manchester
    Posts
    142
    Location

    Run code only if 2 conditions are true

    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
    Attached Images Attached Images

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    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.

  3. #3
    VBAX Contributor
    Joined
    Jul 2011
    Location
    Manchester
    Posts
    142
    Location
    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

  4. #4
    VBAX Contributor
    Joined
    Jul 2011
    Location
    Manchester
    Posts
    142
    Location
    Hi again.

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

  5. #5
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •