Adding a VBA line

nordman66

New Member
Joined
Jul 10, 2014
Messages
9
I have the following function:

'Retuns Plant for a given Sales Org and Order Type combination
Public Function getPlant(strSOrg As String, strOrderType As String, strGivenPlant As String) As String
Dim strCorrectPlant As String

If strOrderType = "ZJTD" Or strOrderType = "ZJTE" Or strOrderType = "ZJTF" Or strOrderType = "ZJTS" Or strOrderType = "ZJTW" Then


If strSOrg = "USSO" Then
strCorrectPlant = "0045"
Else
strCorrectPlant = "0005"
End If
Else
strCorrectPlant = strGivenPlant
End If


getPlant = strCorrectPlant


End Function

and below the first if line I want to add the following

IF (Material = Cascade Material) And (Dldate – Created On) < 90 Then “0042”

where "Material" and "Cascade Material' are headers in a 2 separate tables that will link and "Dldate" and "Created On" are date ranges in the same table.

I know that this is probably straight forward but I am not that familiar with writing VBA and I inherited this database.

Thanks
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Now you can keep altering this function , but you'll have to keep adding Function arguments.
Another way is to make a single macro that runs each of these 'fixes' as update queries. NO CODING NEEDED.

The macro would run these queries:
docmd.openquery "quFixZJ" (to update all ZJTD,etc)
docmd.openquery "quFixNonZJ" (to update the else not ZJ*)
docmd.openquery "quFixUSSO"
docmd.openquery "quFixNonUSSO"
docmd.openquery "quFixMaterialDateRng"


Would that work easier?
 
Upvote 0
What you are suggesting is unfortunately beyond my knowledge skills and I appreciate the offer but as this function has not been updated in 5 years and I don't foresee any additional changes in the future I would like to just add the line to the function which I can then visually understand.

Thanks!!
 
Upvote 0
This is a bit urgent as we are going live with the new data soon. Is someone able to assist me with correctly inserting this new line?
Thanks!!
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,802
Members
449,095
Latest member
m_smith_solihull

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