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

Sub Procedure - How to call it

Status
Not open for further replies.

darinmc

Technical User
Feb 27, 2005
171
GB
I have a private sub procedure, i'm still quite novice at coding.

How would I create a sub procedure, so that when i clicked a command button (say cmdCheck) it would call the procedure using the code below???
The procedure could be called e.g. mailcheck

I would like the procedure to be called on many other cmd buttons as well.

Code:
Private Sub tPassword_Exit(Cancel As Integer)
Dim CntRec, CntRecChase As Integer

CntRec = DCount("[ReadDiary]", "tblDiary", "[ReadDiary] =0 and [FollowOn] <>-1 and [RegNo] =tRegNo")
CntRecChase = DCount("[ReadDiary]", "tblDiary", "[FollowOn] =-1 and [RegNo] =tRegNo")
    If CntRec > 0 Then
    Me.lblNew.Visible = True
    Else
    Me.lblNew.Visible = False
    End If
    If CntRecChase > 0 Then
    Me.lblFollowUp.Visible = True
    Else
    Me.lblFollowUp.Visible = False
    End If
    If CntRec > 0 Or CntRecChase > 0 Then
    Me.cmdStaffDiary.Caption = Me.tName & " - You have messages          NEW = " & CntRec & "             REMINDER = " & CntRecChase
    Me.Box113.Visible = False
    Else
    Me.Box113.Visible = True
    Me.Box113.BackColor = 16768494
    Me.cmdStaffDiary.Caption = "You have NO new Messages / Reminders"
    End If
End Sub

Is there a better and cleaner way of writing the above if statement and how?

Thx Darin
 
Something like this ?
Code:
Private Sub tPassword_Exit(Cancel As Integer)
mailcheck
End Sub

Private Sub mailcheck()
Dim CntRec As Integer, CntRecChase As Integer
CntRec = DCount("ReadDiary", "tblDiary", "ReadDiary=0 AND FollowOn<>-1 AND RegNo=" & Me!tRegNo)
CntRecChase = DCount("ReadDiary", "tblDiary", "FollowOn=-1 AND RegNo=" & Me!tRegNo)
Me!lblNew.Visible = (CntRec > 0)
Me!lblFollowUp.Visible = (CntRecChase > 0)
If CntRec > 0 Or CntRecChase > 0 Then
    Me!cmdStaffDiary.Caption = Me!tName & " - You have messages          NEW = " & CntRec & "             REMINDER = " & CntRecChase
    Me!Box113.Visible = False
Else
    Me!Box113.Visible = True
    Me!Box113.BackColor = 16768494
    Me!cmdStaffDiary.Caption = "You have NO new Messages / Reminders"
End If
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top