Use same code for multiple forms

Koffer08

New member
Local time
Yesterday, 22:42
Joined
Sep 11, 2013
Messages
2
Hi,

I've been trying to figure a way to minimize my code in a module. I currently have three function built excalty the same way to work with three different forms. Each textbox in all the forms are named the same now what I'm trying to do is have the function identify which form called the function and where should the data be. I currently have no coding for it since I have no idea how to even start with this and I've looked all over the place and I can't find my answer.

The plan is

Identify wich form was it requested from. I'm using this right now since this is the easiest I've found.
Code:
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.[B]ActiveForm[/B]MsgBox "Current form is " & frmCurrentForm.Name

Once that is found.

have something like this.

Code:
Select Case frmCurrentForm.Name
Case 1
WorkForm = Form1
 
Case 2
WorkForm = Form2
 
End case

This should make me be able to do

Code:
WorkForm.NameField = "John Smith"

No matter if all three forms are open the data should only go to the one that declared the function.

Please help I've been trying to figure this out for too long.
 
Why not have a parameter to your sub or function as ByRef and type form - then when you call the function you use Me


e.g.

Public Sub mySub(ByRef myForm as Form)

and called as

mySub(Me)
 
Thanks for the reply CJ_London.

I've tried this before and it didn't seem to work. The error generated is Type Mismatch as I called the sub.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom