Code > Module / Class? (1 Viewer)

Ironis

Learning Member...
Local time
Today, 18:34
Joined
Oct 10, 2002
Messages
61
FormCode to Module or Class?

Hey there,

I have a question. I'm working on a planning code, but it seems to get a bit long. Now I want to put the code into modules or classes, to make it more clear to review etc.
Can I do this? and if so, how can I do this?
 
Last edited:

Ironis

Learning Member...
Local time
Today, 18:34
Joined
Oct 10, 2002
Messages
61
So there is no way to use a module / class for the code? I know that with VB it can, but I don't know how to refer to the code that should be used from the formcode. Does anyone know this?
 

chenn

Registered User.
Local time
Today, 22:34
Joined
Apr 19, 2002
Messages
69
Not sure what you are asking, are you wanting to refer to the code in your form class module from somewhere else? If so, put that code into a module and make it public. The call the sub/function from you form and anywhere else.

If this isn't what you are asking, be a little more specific and I'll see what I can do.
 

Ironis

Learning Member...
Local time
Today, 18:34
Joined
Oct 10, 2002
Messages
61
I want the code from a form to be in a class or module, so I have a better overvieuw of the long piece of code. It's about 12 pieces of paper, times 6.. so thats why I want different classes/modules, also so that I can refer to it on multiple forms..
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:34
Joined
Feb 19, 2002
Messages
43,768
If you have common code that is executed for several forms, you can define a public subroutine in a standard module that you can call from each form. Of course, this presumes that the field/control names are also consistant across the forms:

Public Sub CommonCode(frm As Form)
frm.txtCompany = frm.txtCOMPANY_NM
End Sub

Then to execute it:
Call CommonCode(Me)

"Me" is the object reference to the current form. You pass it to the sub and in the sub you use it as you would in the form's class module.
 

Ironis

Learning Member...
Local time
Today, 18:34
Joined
Oct 10, 2002
Messages
61
and how can I call a module or a class if i got the code in there? That would make the overvieuw also better, for revieuwing or changes to the code..
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:34
Joined
Feb 19, 2002
Messages
43,768
You can't call a module or a class, you can only call a subroutine or a function.

If you are trying to move the code to a module simply to make documentation easier, I recommend a different solution. Buy a copy of Total Access Analyzer from fms inc. It is well worth the price. Divide it by your hourly rate and figure out how much time you can spend trying to solve the problem before you would have been better off to pony up the money. Their web site is www.fmsinc.com and you can download a sample of the tool. There are also some excellent papers to read when you visit their site.
 

Users who are viewing this thread

Top Bottom