E
eckert1961
Hello,
I would like to add vbYesNo to the following code that will have the
following result. I want the user to be prompted for, "Does this class run on
Mondays?" If the response is YES then I want the code to run as is. If NO
then I want Monday's to be excluded. Please let me know if any clarification
is required. Thank you.
Option Compare Database
Public Function GetLabel(ClassDayID As Long, ClassDay As Date)
'set up connection and recordset
Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myrecset As New ADODB.Recordset
myrecset.ActiveConnection = cnn1
Dim mySQL As String
mySQL = "SELECT ClassDay FROM tblClassDays WHERE fkClassesID=" & ClassDayID
& " Order by ClassDay asc"
'open the recordset of project days for the project #
'if the date is a special day return the type from tblSpecial days
If DCount("pkSpecDateID", "tblSpecialDays", "dteSpec=#" & ClassDay &
"#") <> 0 Then
GetLabel = DLookup("txtType", "tblSpecialDays", "dteSpec=#" &
ClassDay & "#")
Else
'if the date is a Saturday or Sunday and not a special day
return the label Wknd
If Weekday(ClassDay) = 1 Or Weekday(ClassDay) = 3 Or
Weekday(ClassDay) = 5 Or Weekday(ClassDay) = 7 And DCount("pkSpecDateID",
"tblSpecialDays", "dteSpec=#" & ClassDay & "#") = 0 Then
GetLabel = "Wknd"
Else
'if the date is not a weekend date or special get the loop
through to assign a seq #
myrecset.Open mySQL
Do Until myrecset.EOF
'if date in the project detail record is not a weekend or
special day add to the counter
If Weekday(myrecset!ClassDay) <> 1 Then
If Weekday(myrecset!ClassDay) <> 3 Then
If Weekday(myrecset!ClassDay) <> 5 Then
If Weekday(myrecset!ClassDay) <> 7 Then
If DCount("pkSpecDateID", "tblSpecialDays",
"dteSpec=#" & myrecset!ClassDay & "#") <> 1 Then
c = c + 1
If ClassDay = myrecset!ClassDay Then
GetLabel = "Day " & c
End If
End If
End If
End If
End If
End If
myrecset.MoveNext
Loop
myrecset.Close
End If
End If
Set myrecset = Nothing
End Function
I would like to add vbYesNo to the following code that will have the
following result. I want the user to be prompted for, "Does this class run on
Mondays?" If the response is YES then I want the code to run as is. If NO
then I want Monday's to be excluded. Please let me know if any clarification
is required. Thank you.
Option Compare Database
Public Function GetLabel(ClassDayID As Long, ClassDay As Date)
'set up connection and recordset
Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myrecset As New ADODB.Recordset
myrecset.ActiveConnection = cnn1
Dim mySQL As String
mySQL = "SELECT ClassDay FROM tblClassDays WHERE fkClassesID=" & ClassDayID
& " Order by ClassDay asc"
'open the recordset of project days for the project #
'if the date is a special day return the type from tblSpecial days
If DCount("pkSpecDateID", "tblSpecialDays", "dteSpec=#" & ClassDay &
"#") <> 0 Then
GetLabel = DLookup("txtType", "tblSpecialDays", "dteSpec=#" &
ClassDay & "#")
Else
'if the date is a Saturday or Sunday and not a special day
return the label Wknd
If Weekday(ClassDay) = 1 Or Weekday(ClassDay) = 3 Or
Weekday(ClassDay) = 5 Or Weekday(ClassDay) = 7 And DCount("pkSpecDateID",
"tblSpecialDays", "dteSpec=#" & ClassDay & "#") = 0 Then
GetLabel = "Wknd"
Else
'if the date is not a weekend date or special get the loop
through to assign a seq #
myrecset.Open mySQL
Do Until myrecset.EOF
'if date in the project detail record is not a weekend or
special day add to the counter
If Weekday(myrecset!ClassDay) <> 1 Then
If Weekday(myrecset!ClassDay) <> 3 Then
If Weekday(myrecset!ClassDay) <> 5 Then
If Weekday(myrecset!ClassDay) <> 7 Then
If DCount("pkSpecDateID", "tblSpecialDays",
"dteSpec=#" & myrecset!ClassDay & "#") <> 1 Then
c = c + 1
If ClassDay = myrecset!ClassDay Then
GetLabel = "Day " & c
End If
End If
End If
End If
End If
End If
myrecset.MoveNext
Loop
myrecset.Close
End If
End If
Set myrecset = Nothing
End Function