Using a module for multiple forms

TaiChi56

Registered User.
Local time
Today, 11:29
Joined
Nov 4, 2004
Messages
22
I have a VBA module called modAuto_Fill_New_Record. It auto fills several different fields for me. My problem is I need to use it on 5 different forms. How do I do this. When I write a new form it does not work. So I create another modAuto_Fill_New_Record and it says that I already have one. Do I need just to change the name or add a number to each new module. Hope this makes sense. Thank you.
 
Move the procedures to a standalone module. Change the header so that it accepts a form argument.

Public yourSub(frm as Form)

All your control references in the sub need to be frm.SomeControlName. When you call the procedure pass it the name of the active form.

Call YourSub(Me)
 
Excellent, thank you. I will try this.
 
Pat, I came across this posting and can not quite get it. I have ...

Public Function myReset(frm As Form)
Dim ctrl As Control
For Each ctrl In Forms(frm)
If ctrl.ControlType = acListBox Or ctrl.ControlType = acComboBox Then
ctrl.Value = Null
Else
End If
Next ctrl
End Function

on my forms button I have...
Function Reset()
Call myReset(Me)
End Function

Can you please shed some light on where I am loosing your direction? What I am trying to accomplish is have 1 Resest function that multiple forms can call on.

Thanks
 
Correction In Code

Public Function myReset(frm As Form)
Dim ctrl As Control
'For Each ctrl In Forms(frm)
For Each ctrl in frm
If ctrl.ControlType = acListBox Or ctrl.ControlType = acComboBox Then
ctrl.Value = Null
Else
End If
Next ctrl
End Function


Thanks anyway Pat, I know you read it :)
 

Users who are viewing this thread

Back
Top Bottom