Problem with my 1st ever module

andrewf10

Registered User.
Local time
Today, 20:15
Joined
Mar 2, 2003
Messages
114
Apologies for asking this question but I'm working on my first ever module here.

I've got a large chunk of code that I've copied and pasted onto 16 other forms. Obviously it would be much neater to have it once in a module but I'm having problems. Here's a sample of where I'm at.

******************************
Public Function BOMCODE()
Dim BARCODELINE4 As String
Dim NORMALPACKQTY As String

If (BARCODELINE4 = "Contents 1" And NORMALPACKQTY = "0") Then

QUANTITY_1 = "0.004"
QUANTITY_2 = "1"
QUANTITY_4 = "1"

ElseIf (BARCODELINE4 = "Contents 1" And NORMALPACKQTY = "2") Then

QUANTITY_1 = "0.004"
QUANTITY_2 = "1"
QUANTITY_4 = "2"

End If
End Function

******************************
Now here's the code on 1 of those forms
******************************

Private Sub BARCODELINE4_AfterUpdate()
Call Module1.BOMCODE
End Sub



The afterupdate is calling the module OK but when I step through the code, the module thinks that the BARCODELINE4 and NORMALPACKQTY fields have "" in them.

Am I totally off the beaten track?

Many thanks in advance (again!!)
 
Andrew,

I'm assuming that your function lives in the modules collection
(in the module module1).

Code:
Dim BARCODELINE4 As String 
Dim NORMALPACKQTY As String 

If (BARCODELINE4 = "Contents 1" And NORMALPACKQTY = "0") Then 

QUANTITY_1 = "0.004" 
QUANTITY_2 = "1" 
QUANTITY_4 = "1"


If that is the case, it does not know the values of the two
"Dimmed" strings. They would have to be referred to as

Forms![YourMainForm]![BARCODELINE4]

The same for the QUANTITY variables. Since you have 16 forms
this would not seem to work.

What you have to do is pass the unchanging fields by value and
the Quantity ones by reference. See the help files for examples.

Also, it would be a good idea for your function to return a value
to convey situations where the arguments are invalid.

hth,
Wayne
 
Wayne and Pat,

Huge thanks once more for furthering my education!
Needless to say the code worked perfectly first time...

Andrew
 

Users who are viewing this thread

Back
Top Bottom