event problem.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I seem to be having a problem with my events. I turn them off in code to
process things but I have lost it somewhere... I have set up a watch on
application.enableevents and it breaks on this function...

It breaks on the first line...with events being off but this function does
not turn them off... I cannot figure it out. Any change events can be turned
off some other way? I have searched the code and no where... Please help...

Thanks,
Ernst.

Function CountDaysWithSales(dEnd As Date) As Integer

' ********************************************************
' ** Count Database records with Sales

' ** dEnd - Date of Week Ending Date
' ********************************************************

Dim fld As Field
Dim rst As ADODB.Recordset

Dim sConn As String
Dim sSQL As String

Dim dLast As Date

On Error GoTo ErrHandler
CountDaysWithSales = 0

sFile = ThisWorkbook.Path & DB_FILE

dLast = DateSerial(Year(dEnd), Month(dEnd) + 1, 0) + 1


' Create a new recordset object
Set rst = New ADODB.Recordset

' Connection details
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sFile

'Verify a record
sSQL = "SELECT COUNT([ID]) FROM " & DAY_TABLE & _
" WHERE [Daily Sales]>0 AND Date<#" & dLast & "# " & _
"AND Date>#" & dEnd & "#;"


rst.Open sSQL, sConn

If rst.State = adStateOpen Then
CountDaysWithSales = rst.Fields(0).Value
End If

Done:
rst.Close

Set rst = Nothing
Exit Function

ErrHandler:

CountDaysWithSales = 0
Resume Done

End Function
 
I'm not seeing the connection between Application.EnableEvents and your
function. The function just returns a number (of days with sales). There
doesn't seem to be any event in it.

Perhaps there is some confusion regarding the Application.EnableEvents method.

Unlike Application.ScreenUpdating, once it is set to False it does NOT
automatically return to true at the end of a procedure. You must explicitly
set it back to TRUE.

Often in development stages or testing a procedure, you may have set it to
FALSE near the beginning of a sub, then stopped the procedure in the middle
with debugging or with an error. If the code execution never reaches the end
of your sub (where you should have a line resetting events to true) you will
have to manually reset it in order for you code to work again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top