[AccessD] Form not refreshing--sometimes

John Clark John.Clark at niagaracounty.com
Tue Oct 11 13:21:08 CDT 2005


I've working on an A2K form (frmMonthly) that is sends parameters to
query (qryMonthly), which in turn provides data for a subform
(sfMoDetail) on this same form. Basically you type in an employee number
and a year (both text boxes...yr defaults to current year), choose a
time off type and a month (each using combo boxes), and it fills in a
starting date and ending date, in the fields, "txtBegDate" and
"txtEndDate." The query uses "txtEmpNum", "cboTOType", "txtBegDate" and
"txtEndDate" to return the dates and times that an employee took off
that month.

This works like a charm, if I type in an employee number (10080 is my
test), and pick from the combos w/the mouse...the year is untouched,
because it is already the current year and my test month is JUN, 2005.
However, if I use the keyboard only to pick everything, nothing is
returned, even if I then revert to using the mouse...once I've used the
keyboard, I must exit the form and enter it again, for it to work.

I currently have absolutely no clue as to why this is happening. After
each of the fields (not including "txtEmpNum") the AfterUpdate event
fires and calls a sub called "SetDates." This sub, as you can probably
guess, sets the values of "txtBegDate" and "txtEndDate" and then
requeries the subform. The dates are being filled in correctly, in both
scenarios, and I have temporarily added two text boxes to verify that
the values being passed to the query are what I am expecting. As I was
writing this, it occurred to me that I hadn't tried running the query
directly in my troubleshooting process, while using the keyboard...I
just did and the query itself runs.

The code in the sub, which probably has nothing to do with this, is:

***************************************** BEG CODE SNIPPET
**************************************
Private Sub SetDates()

Dim NumDays As Integer
Dim SummaryText As String

Select Case cboMonth.Value
    Case 1, 3, 5, 7, 8, 10, 12              'Jan, Mar, May, Jul, Aug,
Oct, & Dec have 31 days
        NumDays = 31
    Case 4, 6, 9, 11                        'Apr, Jun, Sep, & Nov have
30 days
        NumDays = 30
    Case 2                                  'February - could be leap
year
        
        If txtYr.Value Mod 100 = 0 Then     'If it is a century year,
it must be div. by 400.
            If txtYr.Value Mod 400 = 0 Then
                NumDays = 29
            Else
                NumDays = 28
            End If
        Else                                'If not century yr, test if
div by 4 for leap yr.
            If txtYr.Value Mod 4 = 0 Then
                NumDays = 29
            Else
                NumDays = 28
            End If
        End If
        
End Select

'Set Beg & End dates for given month, for use as parameters in query
txtBegDate.Value = cboMonth.Value & "/" & 1 & "/" & txtYr.Value
txtEndDate.Value = cboMonth.Value & "/" & NumDays & "/" & txtYr.Value

'Set summary text to let user know exactly what is being queried
SummaryText = "This data represents all " & cboTOType.Value & " time
taken, for employee "
SummaryText = SummaryText & txtEmpNum & ", for " & cboMonth.Value & ",
" & txtYr
lblSummary.Caption = SummaryText

sfMoDetail.Requery

End Sub
***************************************** END CODE SNIPPET
**************************************

Please save my sanity and send me a clue here!

Take care!

John W Clark



More information about the AccessD mailing list