PC Review


Reply
Thread Tools Rate Thread

Assistance with vbYesNo

 
 
eckert1961
Guest
Posts: n/a
 
      20th Apr 2010
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

--
Regards,
Chris
 
Reply With Quote
 
 
 
 
eckert1961
Guest
Posts: n/a
 
      21st Apr 2010
I changed my approach and ended up with the following.

Dim ans As Integer

ans = MsgBox("Does this class run on Mondays?", vbYesNo, "Monday Class?")

If Not IsNull(Me.filter) And (ans = vbYes) Then
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryGetMWF"
Me.Refresh
DoCmd.OpenReport "Attendance", A_PREVIEW, , Me.Form.filter
DoCmd.Maximize
DoCmd.SetWarnings True
ElseIf (ans = vbNo) Then
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryGetWF"
Me.Refresh
DoCmd.OpenReport "Attendance", A_PREVIEW, , Me.Form.filter
DoCmd.Maximize
DoCmd.SetWarnings True
Else
MsgBox "Apply a filter to the form first"
End If

It works great but if anyone has any suggestions on how to improve, it let
me know.
--
Regards,
Chris


"eckert1961" wrote:

> 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
>
> --
> Regards,
> Chris

 
Reply With Quote
 
mcescher
Guest
Posts: n/a
 
      21st Apr 2010
On Apr 20, 9:28*pm, eckert1961 <eckert1...@discussions.microsoft.com>
wrote:
> I changed my approach and ended up with the following.
>
> Dim ans As Integer
>
> ans = MsgBox("Does this class run on Mondays?", vbYesNo, "Monday Class?")
>
> If Not IsNull(Me.filter) And (ans = vbYes) Then
> * * DoCmd.SetWarnings False
> * * DoCmd.OpenQuery "qryGetMWF"
> * * Me.Refresh
> * * DoCmd.OpenReport "Attendance", A_PREVIEW, , Me.Form.filter
> * * DoCmd.Maximize
> * * DoCmd.SetWarnings True
> ElseIf (ans = vbNo) Then
> * * DoCmd.SetWarnings False
> * * DoCmd.OpenQuery "qryGetWF"
> * * Me.Refresh
> * * DoCmd.OpenReport "Attendance", A_PREVIEW, , Me.Form.filter
> * * DoCmd.Maximize
> * * DoCmd.SetWarnings True
> Else
> * * MsgBox "Apply a filter to the form first"
> End If
>
> It works great but if anyone has any suggestions on how to improve, it let
> me know.
> --
> Regards,
> Chris
>
>
>
> "eckert1961" wrote:
> > 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

>
> > --
> > Regards,
> > Chris- Hide quoted text -

>
> - Show quoted text -


Perhaps something like this?

Dim ans As Integer
ans = MsgBox("Does this class run on Mondays?", vbYesNo, "Monday
Class?")
DoCmd.SetWarnings False
If (Not IsNull(Me.Filter) And (ans = vbYes)) Or (ans = vbNo) Then
DoCmd.OpenQuery IIf(ans = vbYes, "qryGetMWF", "qryGetWF")
Me.Refresh
DoCmd.OpenReport "Attendance", A_PREVIEW, , Me.Form.Filter
DoCmd.Maximize
Else
MsgBox "Apply a filter to the form first"
End If
DoCmd.SetWarnings True

Also, it's bit of a moot point, but in your first section of code, a
CASE statement would be very helpful to replace all those IFs.

Hope this helps,
Chris M.
 
Reply With Quote
 
eckert1961
Guest
Posts: n/a
 
      23rd Apr 2010
Thanks Chris,

Your code is much cleaner. I pasted it into the module and everything works
as expected.

I'll also look at implementing your suggestion about using a Case statement
in the other code that I posted. I really appreciate your input.
--
Regards,
Chris


"mcescher" wrote:

> On Apr 20, 9:28 pm, eckert1961 <eckert1...@discussions.microsoft.com>
> wrote:
> > I changed my approach and ended up with the following.
> >
> > Dim ans As Integer
> >
> > ans = MsgBox("Does this class run on Mondays?", vbYesNo, "Monday Class?")
> >
> > If Not IsNull(Me.filter) And (ans = vbYes) Then
> > DoCmd.SetWarnings False
> > DoCmd.OpenQuery "qryGetMWF"
> > Me.Refresh
> > DoCmd.OpenReport "Attendance", A_PREVIEW, , Me.Form.filter
> > DoCmd.Maximize
> > DoCmd.SetWarnings True
> > ElseIf (ans = vbNo) Then
> > DoCmd.SetWarnings False
> > DoCmd.OpenQuery "qryGetWF"
> > Me.Refresh
> > DoCmd.OpenReport "Attendance", A_PREVIEW, , Me.Form.filter
> > DoCmd.Maximize
> > DoCmd.SetWarnings True
> > Else
> > MsgBox "Apply a filter to the form first"
> > End If
> >
> > It works great but if anyone has any suggestions on how to improve, it let
> > me know.
> > --
> > Regards,
> > Chris
> >
> >
> >
> > "eckert1961" wrote:
> > > 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

> >
> > > --
> > > Regards,
> > > Chris- Hide quoted text -

> >
> > - Show quoted text -

>
> Perhaps something like this?
>
> Dim ans As Integer
> ans = MsgBox("Does this class run on Mondays?", vbYesNo, "Monday
> Class?")
> DoCmd.SetWarnings False
> If (Not IsNull(Me.Filter) And (ans = vbYes)) Or (ans = vbNo) Then
> DoCmd.OpenQuery IIf(ans = vbYes, "qryGetMWF", "qryGetWF")
> Me.Refresh
> DoCmd.OpenReport "Attendance", A_PREVIEW, , Me.Form.Filter
> DoCmd.Maximize
> Else
> MsgBox "Apply a filter to the form first"
> End If
> DoCmd.SetWarnings True
>
> Also, it's bit of a moot point, but in your first section of code, a
> CASE statement would be very helpful to replace all those IFs.
>
> Hope this helps,
> Chris M.
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vbYesNo mike allen Microsoft Excel Programming 1 4th Jan 2004 03:59 PM
Re: VBYesNo Bruce M. Thompson Microsoft Access VBA Modules 3 9th Aug 2003 04:05 AM
Re: VBYesNo Lisa B. Microsoft Access VBA Modules 0 7th Aug 2003 05:55 PM
Re: VBYesNo Rick Brandt Microsoft Access VBA Modules 0 7th Aug 2003 05:41 PM
Re: VbYesNo Andy Korth Microsoft Access Form Coding 0 2nd Jul 2003 07:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:08 PM.