Using Custom Warning Boxes

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

magmike

I've created a password change form that UPDATEs the record if the old
password entered on the form matches the password in the record.

When it does and a button is clicked, the SQL is run and the standard
"You are about to update 1 row(s)." is displayed.

I would like to eliminate that and put in my own Yes/No MsgBox that
ask the user if they would really like to change their password. How
would I do that in the following code?

Another subquestion: since the If/Then statement determines that the
entered password and the record password matches, it isn't neccesary
in the SQL statement, correct?

Thanks in advance for your help!

magmike

Note: FindRepName is a combo box on the form populates itself with all
of the available reps from the table, and it's bound column is the
record id (repid).

Begin
------------------
Private Sub passchange_Click()
Dim stSQL As String
Dim stPrompt As String
Dim stControl As String

stSQL = "UPDATE Reps SET Reps.reppassword = [newpass] WHERE
(Reps.repid) = [FindRepName];"
stPrompt = "The old password does not match the record. You must know
the old password in order to change it. Please try again."
stControl = "[FindRepName]"

If [oldpass] = [reppassword] Then
DoCmd.RunSQL stSQL
DoCmd.GoToControl stControl
DoCmd.RunCommand acCmdRefresh
Else
MsgBox stPrompt, vbExclamation
End If

End Sub
 
You can issue an

docmd.SetWarnings false

you code goes here

docmd.SetWarnings True.


However, if you dump te use of docmd.RunSql, and use

currentdb.Execute strSql

Then you will not have to bother playing with the setwarnings. You usually
find the currenetdb.Execute method runs faster as it not wrapped in a
transaction (that gives you the "you are about to update xxxx rows"
message).
 
Back
Top