Hello. Brand new member. First time posting, although I have taken many useful hints and tips from the forum in the past before joining.
I am now asking (begging) for some help.
I have a form, which contains 42 textboxes to create a calendar layout. The code works fine for displaying the calendar and includes the city name in the correct boxes. I have adapted the code from a post I found online...but now I have some superfluous lines of code that refer to tables I don't intend to use. However, if I remove the code or delete the tables I am not using then I get an error message. I could, theoretically, leave the database as it is and ignore the below lines and the tables that associate with them...but it irritates me and I would appreciate any help in getting rid of the lines and the associated tables.
Here is the code(the lines I want to remove are in red):
I am now asking (begging) for some help.
I have a form, which contains 42 textboxes to create a calendar layout. The code works fine for displaying the calendar and includes the city name in the correct boxes. I have adapted the code from a post I found online...but now I have some superfluous lines of code that refer to tables I don't intend to use. However, if I remove the code or delete the tables I am not using then I get an error message. I could, theoretically, leave the database as it is and ignore the below lines and the tables that associate with them...but it irritates me and I would appreciate any help in getting rid of the lines and the associated tables.
Here is the code(the lines I want to remove are in red):
Code:
Option Explicit
Private intMonth As Integer
Private intYear As Integer
Private lngFirstDayOfMonth As Long
Private intFirstWeekday As Integer
Private intDaysInMonth As Integer
Private myArray() As Variant
Private Sub Form_Load()
With Me
.cboMonth = Month(Date)
.cboYear = Year(Date)
End With
Call Main
End Sub
Private Sub cboMonth_AfterUpdate()
On Error GoTo ErrorHandler
Call Main
ExitSub:
Exit Sub
ErrorHandler:
MsgBox "There has been an error. Please reload the form"
Resume ExitSub
End Sub
Private Sub cboYear_AfterUpdate()
On Error GoTo ErrorHandler
Call Main
ExitSub:
Exit Sub
ErrorHandler:
MsgBox "There has been an error. Please reload the form"
Resume ExitSub
End Sub
Private Sub Main()
On Error GoTo ErrorHandler
Call InitVariables
Call InitArray
Call LoadArray
Call PrintArray
ExitSub:
Exit Sub
ErrorHandler:
MsgBox "There has been an error. Please reload the form"
Resume ExitSub
End Sub
Private Sub InitVariables()
On Error GoTo ErrorHandler
intMonth = Me.cboMonth
intYear = Me.cboYear
lngFirstDayOfMonth = CLng(DateSerial(intYear, intMonth, 1))
intFirstWeekday = getFirstWeekday(lngFirstDayOfMonth)
intDaysInMonth = getDaysInMonth(intMonth, intYear)
ExitSub:
Exit Sub
ErrorHandler:
MsgBox "There has been an error. Please reload the form"
Resume ExitSub
End Sub
Private Sub InitArray()
Dim i As Integer
ReDim myArray(0 To 41, 0 To 2)
For i = 0 To 41
myArray(i, 0) = lngFirstDayOfMonth - intFirstWeekday + 1 + i
If Month(myArray(i, 0)) = intMonth Then
myArray(i, 1) = True
myArray(i, 2) = Day(myArray(i, 0))
Else
myArray(i, 1) = False
End If
Next i
End Sub
Private Sub LoadArray()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rsFiltered As DAO.Recordset
Dim strSQL As String
Dim i As Integer
strSQL = "SELECT tblExam.ExamID, tblExam.ExamDate, tblExam.City, " _
& "tblExam.City AS Part1 " _
[COLOR="Red"]& "FROM tblLocations INNER JOIN ((tblCourse INNER JOIN tblLevel ON tblCourse.Level = tblLevel.LevelID) " _
& "INNER JOIN (tblExam INNER JOIN tblTeachers ON tblExam.TeacherID = tblTeachers.TeacherID) " _
& "ON tblCourse.CourseID = tblExam.CourseID) ON tblLocations.LocationID = tblExam.LocationID " _[/COLOR]
& "ORDER BY tblExam.ExamDate;"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
If Not rs.BOF And Not rs.EOF Then
For i = LBound(myArray) To UBound(myArray)
If myArray(i, 1) Then
rs.Filter = "[ExamDate]=" & myArray(i, 0)
Set rsFiltered = rs.OpenRecordset
Do While (Not rsFiltered.EOF)
myArray(i, 2) = myArray(i, 2) & vbNewLine _
& rsFiltered!Part1
rsFiltered.MoveNext
Loop
End If
Next i
End If
rsFiltered.Close
rs.Close
Set rsFiltered = Nothing
Set rs = Nothing
Set db = Nothing
End Sub
Private Sub PrintArray()
On Error GoTo ErrorHandler
Dim strCtlName As String
Dim i As Integer
For i = LBound(myArray) To UBound(myArray)
strCtlName = "txt" & CStr(i + 1)
Controls(strCtlName).Tag = i
Controls(strCtlName) = ""
Controls(strCtlName) = myArray(i, 2)
Next i
ExitSub:
Exit Sub
ErrorHandler:
MsgBox "There has been an error. Please reload the form"
Resume ExitSub
End Sub