Access Help with writting VBA code

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
I need code that will be triggered when a date filed is changed. I want to put a value (the number of days between two dates) in an unbound field on my form "KickOff_A"

I need to "Dim" and then set the values (If that makes any sense).

I know this is wrong but I assume it would be something like:


*******************************
Dim 1a as…
Dim 2a as…..

Set 1a = [KickOff_Actual]-[Date Received]
Set 1aa = [KickOff_Planned]-[Date Received]


‘(A) = Number of days since Date Received


If KickOff_Applicable = “No” Or IsNull(Date Received) or Date Received =”” Then
If IsNull(KickOff_Actual) or KickOff_Actual = “” Then
If IsNull(KickOff_Planned) or KickOff_Planned= “” Then
End If
Else
KICKOFF_A = 1a
End If
Else
KICKOFF_A = 1AA
End If
**********************

With the exception of KickOff_Applicable, these fields are Dates.

Thanks for the Help!!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
What, in words, is the logic behind what you want to do?
 
Last edited:
Upvote 0
Note: Date Received is the name of the field. I didn't name it and I cannot change it. I know its not wise to have a space in a Name.

I want to first check to see if KickOff_Applicable = No (Its a Yes;No combo box) and if the "Date Received" field is not null or void

Then I want to check and see if my KickOff_Actual field has a date in it. If is does I want to Subtract KickOff_Actual date field from the "Date Received" date field. This value would go into the field named KICKOFF_A

If KickOff_Actual field does not have a date in it, I want to check and see if the KickOff_Planned field has a Date in it. If is does have a Date then I want to subtract the KickOff_Planned date field from the "Date Received" field. This value would go into the field named KICKOFF_A
 
Upvote 0
Try this.
Code:
If KickOff_Applicable = "No" Or DateReceived Is Null Or DateReceived = "" Then
    Exit Sub
End If

If IsDate(KickOff_Actual) Then
    KICKOFF_A = DateDiff("d", KickOff_Actual, DateReceived)
ElseIf IsDate(KickOff_Planned) Then
    KICKOFF_A = DateDidd("d", KickOff_Planned, DateReceived)
End If
 
Upvote 0
THANKS! I didn't think about using an IsDate. I appreciate your help, as always.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
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