One field to update based on two other fields data

drmingle

Board Regular
Joined
Oct 5, 2009
Messages
229
I want one field to update based on two other fields information

User selects "status" and inserts "date" request was made, automated due date populates "due date" field in form. 14 and 1 are days...not months or years.

Code:
Private Sub Date_AfterUpdate(Cancel As Integer)
If Me.[Priority] = "Standard Research Request" Then
Me.[DueDate] = Me.[Date] + 14
If Me.[Priority] = "Pricing Dispute" Then
Me.[DueDate] = Me.[Date] + 1
End If

End Sub
Thanks for any help...
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
You could either use ElseIf or a Case statement.
Examples:
Code:
Private Sub Date_AfterUpdate(Cancel As Integer)
    If Me.[Priority] = "Standard Research Request" Then
        Me.[DueDate] = Me.[Date] + 14
    ElseIf Me.[Priority] = "Pricing Dispute" Then
        Me.[DueDate] = Me.[Date] + 1
    'more ElseIf as needed
    End If
End Sub

Private Sub Date_AfterUpdate(Cancel As Integer)
    Select Case Me.[Priority]
    Case Is = "Standard Research Request"
        Me.[DueDate] = Me.[Date] + 14
    Case Is = "Pricing Dispute"
        Me.[DueDate] = Me.[Date] + 1
    'other cases as needed
    End Select
End Sub

You can also use the DateAdd function if +1 or +14 don't do the job. Check out the syntax in Help.

Denis
 
Upvote 0
Thanks SydneyGeek for the help...

I tried both snippets without success.

I'm getting the following:

Error: User-defined type not defined

Can you offer additional help?

Also, I already have "Microsoft DAO 3.6 Object Library" installed...
 
Last edited:
Upvote 0
If could be that Access is choking on your field name. Date, Month, Year, Day, Name ... are all reserved words (either part of VBA, or names of functions in Access) and they can cause you problems. Try renaming the control from Date to RecDate (for example) and try that instead.

Denis
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top