I have a form (frmProjects) for adding money to a PO fund for projects.
On the form I have a combobox (cboStatus) with three options ("Approved", "In Process", "Rejected").
When a user selects "Approved", the amount inputed (txtAmount) is added to the PO (txtPOAmount).
When a user selects "In Process", the amount inputed is added to the Pending Amount field (txtPendingAmount).
This is my code:
I separated the IF structures because when they were together the functionality disappeared (if I chose "In Process", nothing happened).
This was that code:
Another functionality that I would like to add is if a user comes back to an "In Process" record and changes the status to "Approved", the amount in txtAmount is added to txtPOAmount and taken from txtAmountPending.
Would that be too many IF statements and, if not, where in the first embedded IF would I place the statement?
On a side note, would I code that statement as such?
On the form I have a combobox (cboStatus) with three options ("Approved", "In Process", "Rejected").
When a user selects "Approved", the amount inputed (txtAmount) is added to the PO (txtPOAmount).
When a user selects "In Process", the amount inputed is added to the Pending Amount field (txtPendingAmount).
This is my code:
Code:
Private Sub cboStatus_AfterUpdate()
Dim intResponse As Integer
If Me.cboStatus.Value = "Approved" Then
intResponse = MsgBox("You are about to set the Project Status to Approved. By doing so, you will add the Project Amount to the chosen PO. Do you wish to continue?", vbYesNo, "Project Approval")
If intResponse = vbYes Then
Me.txtPOAmount = Me.txtPOAmount + Me.txtAmount
Me.txtApprovalDate.SetFocus
End If
End If
If Me.cboStatus.Value = "In Process" Then
intResponse = MsgBox("You are about to set the Project Status to In Process. By doing so, the PO's funds will not increase until the Status is set to Approved. Continue?", vbYesNo, "Project Pending")
If intResponse = vbYes Then
Me.txtAmountPending = Me.txtAmountPending + Me.txtAmount
Me.cmdSaveProject.SetFocus
Else
Me.cboStatus.SetFocus
End If
End If
End Sub
I separated the IF structures because when they were together the functionality disappeared (if I chose "In Process", nothing happened).
This was that code:
Code:
Private Sub cboStatus_AfterUpdate()
Dim intResponse As Integer
If Me.cboStatus.Value = "Approved" Then
intResponse = MsgBox("You are about to set the Project Status to Approved. By doing so, you will add the Project Amount to the chosen PO. Do you wish to continue?", vbYesNo, "Project Approval")
If intResponse = vbYes Then
Me.txtPOAmount = Me.txtPOAmount + Me.txtAmount
Me.txtApprovalDate.SetFocus
Else
If Me.cboStatus.Value = "In Process" Then
intResponse = MsgBox("You are about to set the Project Status to In Process. By doing so, the PO's funds will not increase until the Status is set to Approved. Continue?", vbYesNo, "Project Pending")
If intResponse = vbYes Then
Me.txtAmountPending = Me.txtAmountPending + Me.txtAmount
Me.cmdSaveProject.SetFocus
Else
Me.cboStatus.SetFocus
End If
End If
End If
End If
End Sub
Another functionality that I would like to add is if a user comes back to an "In Process" record and changes the status to "Approved", the amount in txtAmount is added to txtPOAmount and taken from txtAmountPending.
Would that be too many IF statements and, if not, where in the first embedded IF would I place the statement?
On a side note, would I code that statement as such?
Code:
If cboStatus.OldValue = "In Process" Then
Me.txtPOAmount = Me.txtPOAmount + Me.txtAmount
Me.txtAmountPending = Me.txtAmountPending - Me.txtAmount