-1

I have a chunk of code that is calling a function insertIntoPlannerFile to do some updating as below

 Call insertIntoPlannerFile("supplier 1 po", rowNumber, prForm.po1Edit)
 Call insertIntoPlannerFile("supplier 1 po date", rowNumber, prForm.po1DateEdit)

Here prForm is the form name and po1Edit is the name of a textbox in that form. I have some other textbox also in the form such as po2Edit, po3Edit etc.

Since the above chunk of code is re using, I tried to make this also as a function. So I type the code as below

Function insertModule(objectNumber As String)
      Call insertIntoPlannerFile("supplier " & objectNumber & " po", rowNumber, prForm.po & objectNumber & Edit)
      Call insertIntoPlannerFile("supplier " & objectNumber & " po date", rowNumber, prForm.po & objectNumber & DateEdit)
End Function

And called the function as below

Call insertModule("1")
Call insertModule("2")

But somehow it is not working. Does anyone know how to change it into a re usable function?

5
  • I guess you need to put Edit resp DateEdit into quotes ("Edit" resp. "DateEdit") Commented Sep 25, 2020 at 7:11
  • This question has been asked so many times in the past. Please search stackoverflow Commented Sep 25, 2020 at 7:11
  • @FunThomas No, variable names cannot be variable they have to be hardcoded. Commented Sep 25, 2020 at 7:12
  • @PEH, sorry, you are right, didn't read the question carefully enough. Commented Sep 25, 2020 at 7:14
  • 1
    HERE is one such link. There are many others. Commented Sep 25, 2020 at 7:15

1 Answer 1

1

If you want the numeber in prForm.po1Edit being variable, the only way to do this is using Controls.

prForm.Controls("po" & NumberVariable & "Edit")

because variable names cannot be dynamic.


Note that your Function does not return any values, therefore it should be a procedure Sub:

Sub insertModule(objectNumber As String)
      Call insertIntoPlannerFile("supplier " & objectNumber & " po", rowNumber, prForm.Controls("po" & objectNumber & "Edit"))
      Call insertIntoPlannerFile("supplier " & objectNumber & " po date", rowNumber, prForm.Controls("po" & objectNumber & "DateEdit"))
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.