SamDennis11
New member
- Local time
- Today, 17:24
- Joined
- Jan 21, 2022
- Messages
- 1
Hi everyone,
First post alert - go easy on me!
I'm relatively new to the VBA universe, but I'm trying to improve my knowledge and have run into a roadblock whilst trying to update a forecasting tool/table using some code.
In short, I have historic forecast data from the last 3 financial years (Jul-Jun) and want to populate the next financial year based on last year's data. Some members of the wider team have already begun forecasting for those months, so I need to populate all cells that have not yet been updated using last year's number as a base, so as not to wipe out their work. The update will be large as we have thousands of customers and tens of thousands of products that need to be updated.
My initial idea is to use an If IsNull DLookup to identify the cells that need populating and then use last year's data if the result is 'Null'. However, I'm stuck on the last bit and getting an error with the 'Then' section. Not sure what I need to do next. Any help would be greatly appreciated!!!
Here is where I have got to:
Private Sub Update_F23_Click()
Dim strSQL As String
If IsNull(DLookup("Forecast", "qry_ForecastData", "MasterCustomerID = " & Me.MasterCustomerID & " AND MasterProductID = " & Me.MasterProductID & " AND Mth = #01/07/2022#")) Then
=(DLookup("Forecast", "qry_ForecastData", "MasterCustomerID = " & Me.MasterCustomerID & " AND MasterProductID = " & Me.MasterProductID & " AND Mth = #01/07/2021#")) - this is giving me error: 'Compile Error. Expected: line number or label or statement or end of statement
Thanks in advance,
Sam
First post alert - go easy on me!
I'm relatively new to the VBA universe, but I'm trying to improve my knowledge and have run into a roadblock whilst trying to update a forecasting tool/table using some code.
In short, I have historic forecast data from the last 3 financial years (Jul-Jun) and want to populate the next financial year based on last year's data. Some members of the wider team have already begun forecasting for those months, so I need to populate all cells that have not yet been updated using last year's number as a base, so as not to wipe out their work. The update will be large as we have thousands of customers and tens of thousands of products that need to be updated.
My initial idea is to use an If IsNull DLookup to identify the cells that need populating and then use last year's data if the result is 'Null'. However, I'm stuck on the last bit and getting an error with the 'Then' section. Not sure what I need to do next. Any help would be greatly appreciated!!!
Here is where I have got to:
Private Sub Update_F23_Click()
Dim strSQL As String
If IsNull(DLookup("Forecast", "qry_ForecastData", "MasterCustomerID = " & Me.MasterCustomerID & " AND MasterProductID = " & Me.MasterProductID & " AND Mth = #01/07/2022#")) Then
=(DLookup("Forecast", "qry_ForecastData", "MasterCustomerID = " & Me.MasterCustomerID & " AND MasterProductID = " & Me.MasterProductID & " AND Mth = #01/07/2021#")) - this is giving me error: 'Compile Error. Expected: line number or label or statement or end of statement
Thanks in advance,
Sam