Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help wih "public" thingys please 1

Status
Not open for further replies.

nevstic

Instructor
Joined
Jul 30, 2002
Messages
98
Location
GB
hi everyone could you help me understand public functions or global things with the following example please.
I have the folowing piece of code which helps me to "check digit" an eight figure number.It is on a bound text box in a form and only refers to that text box.IE using "Me"
What I would like to do is make this code available to other text boxes in other forms.I think that you call this a global module (I'm a learner here).

Private Sub HAWBNO_Enter()
If IsNumeric(Me!AWP) Then
If Val(Left(Me!AWBNO, 7)) Mod 7 = Val(Right(Me!AWBNO, 1)) Then
Me!AWBNO.ForeColor = 16711680
Else 'error in check digit
MsgBox "ERROR ! AWB CHECK DIGIT", 48, "ERROR"
End If
End If
End Sub
Please try to keep it in simple language as I am trying to learn from scratch here.
Many thanks for your patience.
best rgds
Nick
 
Well you need to convert this into a public function that takes a couple of parameters instead of referencing two fields on your form. SOmething like:
Code:
Public Function CheckDigit(ctlAWP As Control, ctlAWBNO As Control)
If IsNumeric(ctlAWP.Value) Then
    If Val(Left(ctlAWBNO.Value, 7)) Mod 7 = Val(Right(ctlAWBNO.Value, 1)) Then
        ctlAWBNO.ForeColor = 16711680
    Else 'error in check digit
        MsgBox "ERROR ! AWB CHECK DIGIT", 48, "ERROR"
    End If
End If
End Function
Put this code in a Module of its own, rather than in a form's module and then it should be available to multiple forms.

To call this function from your original form, put the following in the OnEnter event of the HAWBNO field:
Code:
Private Sub HAWBNO_Enter()
    Call CheckDigit(Me.AWP, Me.AWBNO)
End Sub
Hope this helps.

[pc2]
 
Many many thanks for your quick reply, I will work on this.
thanks also for your explanation.

best rgds
Nick
 
Hi there again
that worked just beautifully ! and also helped me to understand. Could I prevail on you to explain on other thing
for me.

Could I have used the Control scource for referencing the name of this public function or is that something completely different ?
rgds
Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top