Simpler way to use the same code in different places?
I find myself using the same piece of code in different places. Just wondering is there a way I can store the code, and call it later?
So for example, I have alot of Date fields on my forms...
And I'm using the following code in txtDateOfBooking
I have atleast a couple of more txt date fields (like txtDateOfEnquiry & txtDateOfCancel).
Now can I store the above code, and then change the above to
I'd find it "cleaner" and less "bloated" to use this method. It's also alot easier to manage, if I want to tweak/change code.
Hopefully, you know what I mean, and I'm not talking gibberish.
Cheers.
I find myself using the same piece of code in different places. Just wondering is there a way I can store the code, and call it later?
So for example, I have alot of Date fields on my forms...
And I'm using the following code in txtDateOfBooking
Code:
Private Sub txtDateOfBooking_BeforeUpdate(Cancel As Integer)
If Weekday(Me.txtDateOfBooking, vbSaturday) <= 2 Then
Cancel = (MsgBox("The Booking Date is on a " & _
Format(Me.txtDateOfBooking, "dddd") & vbCrLf & vbCrLf & _
"Do you want to keep this date?" _
, vbYesNo + vbQuestion) = vbNo)
If Cancel Then Me.txtDateOfBooking.Undo
End If
If Me.txtDateOfBooking < Date Then
Cancel = (MsgBox("The Booking Date takes places in the past" & vbCrLf & vbCrLf & _
"Do you want to keep this date?" _
, vbYesNo + vbQuestion) = vbNo)
If Cancel Then Me.txtDateOfBooking.Undo
End If
End Sub
I have atleast a couple of more txt date fields (like txtDateOfEnquiry & txtDateOfCancel).
Now can I store the above code, and then change the above to
Code:
Private Sub txtDateOfBooking_BeforeUpdate(Cancel As Integer)
Call Date_Check_Fun
End Sub
Code:
Private Sub txtDateOfEnquiry_BeforeUpdate(Cancel As Integer)
Call Date_Check_Fun
End Sub
Code:
Private Sub txtDateOfCancel_BeforeUpdate(Cancel As Integer)
Call Date_Check_Fun
End Sub
Hopefully, you know what I mean, and I'm not talking gibberish.
Cheers.
Last edited: