help w/ vb code

Purdue22

Registered User.
Local time
Today, 07:39
Joined
May 11, 2001
Messages
25
I have a txt box 'Date Received' in which I use the calendar control to input the date. I also have a combo box 'Priority' and another txt box 'Priority Date'. When I select a value from the combo box it auto fills 'Priority Date'. What I want is when I change the date received txt box I want the code to run again and update the 'Priority Date'. Right now after I enter a date into the date received txt box, select a priority, and then decide to change the date received the code does not automatically run again. I have to reselect the priority cmbbox so that the correct date will show in the priority date.

Here is the code:

Private Sub Priority_Change()

If Priority = "A" Then
Priority_Date = Date_Received + 1
ElseIf Priority = "B" Then
Priority_Date = Date_Received + 3
ElseIf Priority = "C" Then
Priority_Date = Date_Received + 7
ElseIf Priority = "D" Then
Priority_Date = Date_Received + 7
ElseIf Priority = "E" Then
Priority_Date = Date_Received + 14
ElseIf Priority = "O" Then
Status = "A&I"
End If

Private Sub Date_Received_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Show Calendar and set its date.
Calendar.Visible = True
Calendar.SetFocus
'Set to today if Date Received has no value.
Calendar.Value = IIf(IsNull(Date_Received), Date, Date_Received.Value)


End Sub

Private Sub Calendar_Click()
Date_Received.Value = Calendar.Value
Date_Received.SetFocus
Calendar.Visible = False

End Sub

Private Sub Calendar2_Click()
Date_Customer_up.Value = Calendar2.Value
Date_Customer_up.SetFocus
Calendar2.Visible = False

End Sub
Private Sub Date_Customer_up_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Show Calendar and set its date.
Calendar2.Visible = True
Calendar2.SetFocus
' Set to today if Date Customer Up has no value.
Calendar2.Value = IIf(IsNull(Date_Customer_up), Date, Date_Customer_up.Value)

End Sub

Any help would be appreciated!
 
Purdue22,

you could use the AfterUpdate event of the DateReceived text box. AfterUpdate is triggered once the contents of the textbox have been altered...

Private Sub Date_Received_AfterUpdate()
    '-- code here to update priority date...
End Sub

Hope that helps

axa

[This message has been edited by axa (edited 08-14-2001).]
 
Thanks for the suggestion, but I still cannot get it to run the priority code again after I have already entered a date and selected a priority then try to change the date received. Lets say I enter 8/13/01 into date receied txt box, select priority 'A', and it auto fills priority date(Date Received +1)with 8/14/01. Then I decide to change the date received to 8/15/01. It won't run the code again unless I select the priority. Is there a way to maybe requery to run the code?
 
Since the value of the field is derived from two other fields in the same row, the third field should not be stored in the table. You should calculate it whenever you need it.

That said, you would need to replicate the code from the AfterUpdate event of the Priority column in the AfterUpdate event of the DateReceived column. But you would have to check Priority for null because you can't calculate the third field without the presence of both the Priority and DateReceived fields. I would create a public function in a standard code module:

Code:
Public Function CalcPriorityDt(DateReceived As Date, PriorityCd As String) As Date
Select Case PriorityCd
    Case "A" 
        CalcPriorityDt = DateReceived + 1
    Case "B" 
        CalcPriorityDt = Date_Received + 3
    Case "C" 
        CalcPriorityDt = Date_Received + 7
    Case "D" 
        CalcPriorityDt = Date_Received + 7
    Case = "E"  
        CalcPriorityDt = Date_Received + 14
    Case Else
        CalcPriorityDt = Null
End Select
End Function

Then in the AfterUpdate event of the two fields - 

Me.Priority_Date = CalcPriority(Me.Date_Received, Me.Priority)
If IsNull(CalcPriority(Me.Date_Received, Me.Priority)) Then
    Me.Status "A&I"
End If

[This message has been edited by Pat Hartman (edited 08-14-2001).]
 

Users who are viewing this thread

Back
Top Bottom