Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Location
    Cleveland USA
    Posts
    184

    Smile Unanswered: Drop down box properties & code

    I have a drop down box on a form with three status options: Open, Closed and Ongoing. What I want to happen is that if the user attempts to Close the record, I want to first check that all the items are 100% complete. If not, I want the status to reset.

    The code works OK if they're trying to choose Close, but they can't change the status from Open to Ongoing, or vice versa. Is there a property for the dropdown box for 'selected'? If so, I would use that and then only activate the code if they are trying to change it to 'Closed'.


    Here is the code:
    -------------------------------------------------------
    Private Sub txtStatus_Dirty(Cancel As Integer)
    'Verify that all subtasks are completed before closing the Event

    If Me.Status.Value <> "Closed" Then 'Run this whenever the user attempts to close the Event
    Dim intCheckComplete
    intCheckComplete = 100

    'Find a subtask for this event where [PercentComplete] is not 100%
    intCheckComplete = DMin("[PercentComplete]", "[tblSubTasks]", "[Event] = " & Me.EventNumber.Value)

    If intCheckComplete < 100 Then 'undo the change
    Cancel = True
    MsgBox "This Event has incomplete subtasks and therefore cannot be closed.", vbExclamation, "CANNOT CLOSE"
    End If

    End If

    End Sub

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    can your combo have a value "Closed"?
    if not, <> "Closed" is always true!

    stick this just before your If me.status line
    msgbox "My combo .Value is " & me!status.value
    and see what happens.

    ???

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Aug 2003
    Location
    Cleveland USA
    Posts
    184
    The box can have a value of "closed". For example, if someone sees it's closed when it shouldn't be (because of old db programming that didn't validate for 100% complete), and can change from "Closed" to "Open".

    As I have it right now, I can't check the value because it's still holding the old value, not what they're changing it to. I've been doing some other validation checks and think I'll try BeforeUpdate. I think OnDirty is checking it too early.

  4. #4
    Join Date
    Aug 2003
    Location
    Cleveland USA
    Posts
    184

    In case you couldn't rest 'til you heard the answer...

    I had to use BeforeUpdate instead of OnDirty. Here's the code in case you're dying to see it. Thanks for your input because it triggered the right solution.

    ------------------------------------------------
    Private Sub txtStatus_BeforeUpdate(Cancel As Integer)
    'Verify that all subtasks are completed before closing the Event

    If Me.txtStatus.Value = "Closed" Then 'Run this whenever the user attempts to close the Event
    Dim intCheckComplete
    intCheckComplete = 100

    'Find a subtask for this event where [PercentComplete] is not 100%
    intCheckComplete = DMin("[PercentComplete]", "[tblSubTasks]", "[Event] = " & Me.EventNumber.Value)

    If intCheckComplete < 100 Then 'undo the change
    Me.Undo
    MsgBox "This Event has incomplete subtasks and therefore cannot be closed.", vbExclamation, "CANNOT CLOSE"
    End If

    End If
    End Sub

Posting Permissions

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