The following sub procedure has a problem with the line of code in red.
I have created a grid (12 rows by 31 columns) on a form and I'm using it to display bookings. Since the start period for each item being booked varies, which month comes first - and so, comes at the top of the form - will also vary. This means the number of cells in each row needs to change to suit the month label for the row. All of this is working just fine.
The problem I have is with the lines of code in red, in the following sub procedure. In brief, this code:
1) Loops through all controls on a form
2) Checks if a control is a textbox
3) Checks if the textbox name contains an identifying letter
4) Where the value in the textbox is within a certain date range, highlights the box in yellow
As I say, all is working well, apart from that one part in red.
For example, if I pass in a value of liMaxDay = 28 (for February), the code will highlight up to day 24 for that month and no higher. However, if I change the line and hardcode in 28, instead of using the variable, all boxes up to 28 get highlighted.
I've used a message box to check that liMaxDay is set to the correct value, both before and after the problem lines.
If I remove the red lines completely, all text boxes up to 31 are highlighted, which is obviously not what I need.
I'm hoping I'm missing something obvious here (as is my wont).
Any ideas?
I have created a grid (12 rows by 31 columns) on a form and I'm using it to display bookings. Since the start period for each item being booked varies, which month comes first - and so, comes at the top of the form - will also vary. This means the number of cells in each row needs to change to suit the month label for the row. All of this is working just fine.
The problem I have is with the lines of code in red, in the following sub procedure. In brief, this code:
1) Loops through all controls on a form
2) Checks if a control is a textbox
3) Checks if the textbox name contains an identifying letter
4) Where the value in the textbox is within a certain date range, highlights the box in yellow
As I say, all is working well, apart from that one part in red.
For example, if I pass in a value of liMaxDay = 28 (for February), the code will highlight up to day 24 for that month and no higher. However, if I change the line and hardcode in 28, instead of using the variable, all boxes up to 28 get highlighted.
I've used a message box to check that liMaxDay is set to the correct value, both before and after the problem lines.
If I remove the red lines completely, all text boxes up to 31 are highlighted, which is obviously not what I need.
I'm hoping I'm missing something obvious here (as is my wont).
Any ideas?
Code:
Sub Format_Selected_Dates(liMaxDay, strRefLetter As String, liStartDay As Integer, liEndDay As Integer)
Dim ctl As Control
Dim strEndLetter As String
If liStartDay <= liEndDay Then
For Each ctl In Me.Controls
If Right(Left(ctl.name, 4), 1) = strRefLetter Then
If ctl.ControlType = acTextBox Then
If ctl.Value >= liStartDay Then
If ctl.Value <= liEndDay Then
If ctl.ForeColor <> vbWhite Then
Call Format_Selected_Date(ctl)
End If
End If
End If
End If
End If
Next ctl
Else
For Each ctl In Me.Controls
If Right(Left(ctl.name, 4), 1) = strRefLetter Then
If ctl.ControlType = acTextBox Then
If ctl.Value >= liStartDay Then
[COLOR=red] [B]If ctl.Value <= liMaxDay Then[/B][/COLOR]
Call Format_Selected_Date(ctl)
[COLOR=red][B]End If
[/B][/COLOR] End If
End If
End If
Next ctl
strEndLetter = Increment_Letter(strRefLetter)
For Each ctl In Me.Controls
If Right(Left(ctl.name, 4), 1) = strEndLetter Then
If ctl.ControlType = acTextBox Then
If ctl.Value <= liEndDay Then
Call Format_Selected_Date(ctl)
End If
End If
End If
Next ctl
End If
End Sub