craigglenn
Technical User
Ok I have spend days trying to figure this out and have read post simular to my problem but can't quit get it.
I have a single report, off of one table, no joins.
I have and UB text box in the report header.
All I want to do using the code below found in the on open event of the report is the the select case rday section to set the value of the textbox to the relevant Day, ie "Monday" if case 1 is true.
Thanks in advance for your help.
Option Compare Database
Private Sub Report_NoData(Cancel As Integer)
MsgBox ("No records found for specified route."
Cancel = True
End Sub
Private Sub Report_Open(Cancel As Integer)
Dim routeN As Integer
Dim rday As Integer
Dim theQuery As String
Dim dayField As String
GetRouteDay rday 'prompt for route day
GetRouteNum routeN 'prompt for route number
Select Case rday
Case 1
dayField = "PropSwpMonday"
Me.OrderBy = "[PropPriorityMonday]"
Case 2
dayField = "PropSwpTuesday"
Me.OrderBy = "[PropPriorityTuesday]"
Case 3
dayField = "PropSwpWednesday"
Me.OrderBy = "[PropPriorityWednesday]"
Case 4
dayField = "PropSwpThursday"
Me.OrderBy = "[PropPriorityThursday]"
Case 5
dayField = "PropSwpFriday"
Me.OrderBy = "[PropPriorityFriday]"
Case 6
dayField = "PropSwpSaturday"
Me.OrderBy = "[PropPrioritySaturday]"
Case 7
dayField = "PropSwpSunday"
Me.OrderBy = "[PropPrioritySunday]"
End Select
Me.OrderByOn = True
theQuery = "Select * From mainProperty Where " & dayField & "=" & routeN & ";"
Me.RecordSource = theQuery
End Sub
Private Function GetRouteNum(routeN) As Integer
On Error GoTo ErrorHandler
Dim message, title
message = "Enter Route Number:"
title = "Route Number"
routeN = InputBox(message, title)
Exit Function
ErrorHandler:
Select Case Err.Number
Case 13
MsgBox ("You must enter a valid route number"
Case Else
MsgBox ("You must enter a valid route number"
End Select
Resume
End Function
Private Function GetRouteDay(rday) As Integer
On Error GoTo ErrorHandler
Dim message, title
message = "Enter number for day of route:" + (Chr(13)) + "1. Monday" + (Chr(13)) + "2. Tuesday" + (Chr(13)) + "3. Wednesday" + (Chr(13)) + "4. Thursday" + (Chr(13)) + "5. Friday" + (Chr(13)) + "6. Saturday" + (Chr(13)) + "7. Sunday"
title = "Route day"
InvalidDay:
rday = InputBox(message, title)
Select Case rday
Case "1", "2", "3", "4", "5", "6", "7"
Exit Function
Case Else
MsgBox ("You must enter a valid Day Number"
GoTo InvalidDay
End Select
ErrorHandler:
Select Case Err.Number
Case 13
MsgBox ("You must enter a valid day"
Case Else
MsgBox ("You must enter a valid day"
End Select
Resume
End Function
I have a single report, off of one table, no joins.
I have and UB text box in the report header.
All I want to do using the code below found in the on open event of the report is the the select case rday section to set the value of the textbox to the relevant Day, ie "Monday" if case 1 is true.
Thanks in advance for your help.
Option Compare Database
Private Sub Report_NoData(Cancel As Integer)
MsgBox ("No records found for specified route."
Cancel = True
End Sub
Private Sub Report_Open(Cancel As Integer)
Dim routeN As Integer
Dim rday As Integer
Dim theQuery As String
Dim dayField As String
GetRouteDay rday 'prompt for route day
GetRouteNum routeN 'prompt for route number
Select Case rday
Case 1
dayField = "PropSwpMonday"
Me.OrderBy = "[PropPriorityMonday]"
Case 2
dayField = "PropSwpTuesday"
Me.OrderBy = "[PropPriorityTuesday]"
Case 3
dayField = "PropSwpWednesday"
Me.OrderBy = "[PropPriorityWednesday]"
Case 4
dayField = "PropSwpThursday"
Me.OrderBy = "[PropPriorityThursday]"
Case 5
dayField = "PropSwpFriday"
Me.OrderBy = "[PropPriorityFriday]"
Case 6
dayField = "PropSwpSaturday"
Me.OrderBy = "[PropPrioritySaturday]"
Case 7
dayField = "PropSwpSunday"
Me.OrderBy = "[PropPrioritySunday]"
End Select
Me.OrderByOn = True
theQuery = "Select * From mainProperty Where " & dayField & "=" & routeN & ";"
Me.RecordSource = theQuery
End Sub
Private Function GetRouteNum(routeN) As Integer
On Error GoTo ErrorHandler
Dim message, title
message = "Enter Route Number:"
title = "Route Number"
routeN = InputBox(message, title)
Exit Function
ErrorHandler:
Select Case Err.Number
Case 13
MsgBox ("You must enter a valid route number"
Case Else
MsgBox ("You must enter a valid route number"
End Select
Resume
End Function
Private Function GetRouteDay(rday) As Integer
On Error GoTo ErrorHandler
Dim message, title
message = "Enter number for day of route:" + (Chr(13)) + "1. Monday" + (Chr(13)) + "2. Tuesday" + (Chr(13)) + "3. Wednesday" + (Chr(13)) + "4. Thursday" + (Chr(13)) + "5. Friday" + (Chr(13)) + "6. Saturday" + (Chr(13)) + "7. Sunday"
title = "Route day"
InvalidDay:
rday = InputBox(message, title)
Select Case rday
Case "1", "2", "3", "4", "5", "6", "7"
Exit Function
Case Else
MsgBox ("You must enter a valid Day Number"
GoTo InvalidDay
End Select
ErrorHandler:
Select Case Err.Number
Case 13
MsgBox ("You must enter a valid day"
Case Else
MsgBox ("You must enter a valid day"
End Select
Resume
End Function