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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb global question 1

Status
Not open for further replies.

nevstic

Instructor
Jul 30, 2002
98
0
0
GB
Firstly happy new year all.

I wonder if one of you good people could show me the way
to make the following available to all forms rather than just one control on one form.I think they call it a global

I have the following check digit code for an 8 figure number, using the mod method.This aplies to one control on one form , but I would like to make it a function that I could refer to anywhere else.

Private Sub HAWBNO_Enter()
If IsNull(Me!AWBNO) Then
DoCmd.GoToControl "awbno"
Else
If IsNumeric(Me!AWP) Then
'compare first 7 digits with 8th.Mod operator returns remainder
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"
Me!AWBNO.ForeColor = 255
DoCmd.GoToControl "AWBNO"
End If
End If
End If
End Sub
Mucho appreciate any help with this.
best rgds
Nick
 
hi

change Private Sub to Public Sub.
Maybe create a separate module with all your public functions.
you can even use it in a query
 
p27br said:
change Private Sub to Public Sub.
It is not possible to use this code with all forms by changing [purple]Private[/purple] to [purple]Public[/purple] . There are references to Current form(Me). What you will do with that?
I think you have break the code into different [purple]functions[/purple].
Unfortunately I am unable to write a function...
regrards

Zameer Abdulla
Visit Me
 
yes it is possible, you just need to pass the form as a parameter :

Public Sub HAWBNO_Enter(frm as Form)

then replace Me by frm in the code
 
Thanks p27 and Zameer

this is new to me, would either of you have a simple example
on hand that I could try to understand ?

thanks and regards
Nick
 
nevstic

Private Sub HAWBNO_Enter(frm As Form)
If IsNull(frm!AWBNO) Then
DoCmd.GoToControl "awbno"
Else
If IsNumeric(frm!AWP) Then
'compare first 7 digits with 8th.Mod operator returns remainder
If Val(Left(frm!AWBNO, 7)) Mod 7 = Val(Right(frm!AWBNO, 1)) Then
frm!AWBNO.ForeColor = 16711680
Else 'error in check digit
MsgBox "ERROR ! AWB CHECK DIGIT", 48, "ERROR"
frm!AWBNO.ForeColor = 255
DoCmd.GoToControl "AWBNO"
End If
End If
End If
End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top