SetWarnings False, but still want count

  • Thread starter Thread starter magmike
  • Start date Start date
M

magmike

I have a button for changing the date of set items. A user can click
it, to change the date of all items set for a date of 10/14/2008 to
10/15/2008, for example. I've set the warnings to false, but would
like to present a count of records changed, or to be changed. How
could I do that?

Thanks in advance!
magmike
 
See:
    Action queries: suppressing dialogs, while knowing results
at:
   http://allenbrowne.com/ser-60.html

--
Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.







- Show quoted text -

My query has perameters that are entered by the user (which date do
they want to change to which date?) so this isn't going to work for
me. I tried, but the code can't find the perameters. I tried using my
normal code (with warnings turned off)and then using the second line
in this example to report the number of records involved:

MsgBox DBEngine(0)(0).RecordsAffected & " record(s) affected."

But it reports 0 no matter the results. Is there a way with my current
code which turns the warnings off, to at least report the number of
records affected?

Code:

Private Sub DateOnly_Click()
On Error GoTo Err_DateOnly_Click

Dim stDocName As String

DoCmd.Close

stDocName = "CallBackQuickChange (Date Only)"

DoCmd.SetWarnings False
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings True
MsgBox DBEngine(0)(0).RecordsAffected & " record(s) affected."

Exit_DateOnly_Click:
Exit Sub

Err_DateOnly_Click:
MsgBox Err.Description
Resume Exit_DateOnly_Click
End Sub


magmike
 
That is because you are getting a different instantiation of the
database using DbEngine(0)(0) from when you executed the code. Try code
more like the following.


Dim dbAny as DAO.Database
Set dbAny = DbEngine(0)(0)

dbAny.Execute (StrSQL,dbFailonError)
msgbox dbany.RecordsAffected & " records changed"

Set dbany = Nothing

Posting one snippet of a code routine does make it hard to guess what
has gone wrong. At a minimum, you should have posted the line that
executed the query.


'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
Perhaps you could supply the parameter like this:

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = CurrentDb()
Set qdf = db.Querydefs("Query1")
qdf.Parameters("[Forms].[Form1].[Text0]") = [Forms].[Form1].[Text0]
qdf.Execute, dbFailOnError

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

See:
Action queries: suppressing dialogs, while knowing results
at:
http://allenbrowne.com/ser-60.html

My query has perameters that are entered by the user (which date do
they want to change to which date?) so this isn't going to work for
me. I tried, but the code can't find the perameters. I tried using my
normal code (with warnings turned off)and then using the second line
in this example to report the number of records involved:

MsgBox DBEngine(0)(0).RecordsAffected & " record(s) affected."

But it reports 0 no matter the results. Is there a way with my current
code which turns the warnings off, to at least report the number of
records affected?

Code:

Private Sub DateOnly_Click()
On Error GoTo Err_DateOnly_Click

Dim stDocName As String

DoCmd.Close

stDocName = "CallBackQuickChange (Date Only)"

DoCmd.SetWarnings False
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings True
MsgBox DBEngine(0)(0).RecordsAffected & " record(s) affected."

Exit_DateOnly_Click:
Exit Sub

Err_DateOnly_Click:
MsgBox Err.Description
Resume Exit_DateOnly_Click
End Sub


magmike
 
Back
Top