Message box how many records have been update

G

Guest

Hi,
I have a Update query that is openned via a form name Updateform
I really want to have a message box tell the user that how many records have been updated. How can I do this? the following is the code that John help me with.

Private Sub cmdUpdate_Click()
Dim qd As Querydef
Dim db As DAO.Database
Dim prm As Parameter
Set db = CurrentDb
Set qd = db.Querydefs("RupdateFacultyAndLocation")
For Each prm In qd.Parameters
prm.Value = Eval(prm.Name)
Next prm
qd.Execute dbFailOnError
End Sub

Regards,
 
M

Marc

Le Tran said:
Hi,
I have a Update query that is openned via a form name Updateform
I really want to have a message box tell the user that how many records
have been updated. How can I do this? the following is the code that John
help me with.
Private Sub cmdUpdate_Click()
Dim qd As Querydef
Dim db As DAO.Database
Dim prm As Parameter
Set db = CurrentDb
Set qd = db.Querydefs("RupdateFacultyAndLocation")
For Each prm In qd.Parameters
prm.Value = Eval(prm.Name)
Next prm
qd.Execute dbFailOnError
End Sub
Hi,
I'm not sure if recordcount is available on qdf - check that first.
Otherwise -
Dim rst as recordset

rst.Open qd....
Num_recs = rst.RecordCount ' if this is not supported by the driver a 0
or -1 is returned then you need the next loop as well

Num_recs = 0
While not rst.EOF
Num_recs = Num_recs + 1
rst.MoveNext
Wend

rst.Close

HTH
Marcelle
 
J

John W. Vinson

-----Original Message-----
Hi,
I have a Update query that is openned via a form name Updateform
I really want to have a message box tell the user that
how many records have been updated. How can I do this?
the following is the code that John help me with.
Private Sub cmdUpdate_Click()
Dim qd As Querydef
Dim db As DAO.Database
Dim prm As Parameter
Set db = CurrentDb
Set qd = db.Querydefs("RupdateFacultyAndLocation")
For Each prm In qd.Parameters
prm.Value = Eval(prm.Name)
Next prm
qd.Execute dbFailOnError

Just use the querydef's RecordsAffected property:

MsgBox qd.RecordsAffected & " records were updated",
vbOKOnly

John W. Vinson
 

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

Top