visual basic code

Purdue22

Registered User.
Local time
Today, 11:46
Joined
May 11, 2001
Messages
25
When priotity = D then I want the priority date = date received + 14 and also the status to equal "follow- up". I cannot get the txtbox status to show "follow-up"

Any suggestions?

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 + 14
ElseIf Priority = "E" Then
Priority_Date = Date_Received + 28
End If
If Priority = "D" Then
Status = "Follow-up"
End If
Dim var As String
var = ""
If Priority = "Z" Then
Status = "Internal"
ElseIf Priority <> "Z" Then
Status = var
End If
End Sub
 
Hello,


Your code is kind of confusing, but first of all Access won't recognise just a field name. It will give you an error of an undeclared variable. Try using ME.ControlName for all of your fields (ME.Priority). This tells Access that you want the form you are working on and to take the value from that control. Also you might want to go to the help file and type "Select Case" . This is a better way then all those Else If statements.


HTH
Robert
 
Your trouble may be caused by having control names that are the same as column names. If you made the form using the wizard, Access probably gave the controls the same name as their cooresponding control source. If that is the case, change the control names. I usually just prefix them with txt so the control that holds the Priority column would be named txtPriority. Access can't tell if your code is referring to a control or a table/query field if they both have the same name.

Also a case statement is more appropriate for this type of condition checking.
 
Your logic is contradicting itself. Your 3rd If statement *ElseIf Priority <> "Z" Then
Status = var* is setting status back to "" for Priority "D". You need an Exit Sub statement after setting Status to "Follow-up" for Priority "D".

Chris
 

Users who are viewing this thread

Back
Top Bottom