Trying to eliminate spaghetti code

Trying to eliminate spaghetti code

Hi,

I have been using the following code to generate an autonumber field for various forms, just changing the values as required depending on what I have named them in the forms (e.g. intClientID, intContactID, intVenueID, etc.)

   
  1. varMaxValue  =  frmMaxValue  [ID != 0];

    input.intClientID = (varMaxValue.intClientVal  +  1);

    varMaxValue.intClientVal = (varMaxValue.intClientVal  +  1);



I would like to get rid of the spaghetti code, and simply call a function, but am having issues.  The form where I store the values is called frmMaxValue, and it has several different integer fields (e.g. intClientVal, intContactVal, etc.)

I tried the following code:

   
  1.  void basMaxValue(string varFormName, int intMaxValue, int intPrimaryKey)
    {
    varMaxValue = varFormName [ID != 0];
    input.intPrimaryKey = (varMaxValue.intMaxValue + 1);
    varMaxValue.intMaxValue = (varMaxValue.intMaxValue + 1);
    }




But I keep getting the following error message: Error at line: 3 Form varFormName does not exist in this application

I tried it without delcaring varFormName and just using the actual form name, but got the same error.

Any direction I should be going with this?


Thanks


Leo Saumure