troubleshooting Question

In my Form_BeforeUpdate subroutine, when the user updates a field, I send a MsgBox, but it comes up twice and I don't know why ?

Avatar of zimmer9
zimmer9Flag for United States of America asked on
Microsoft Access
13 Comments1 Solution253 ViewsLast Modified:
I am developing an Access application using an ADP file. I use Access as the front end and SQL Server as the back end database.

On a form, if I modify an existing record and intentionally update a field named BRANCH with an erroneous BRANCH value, I get a MsgBox to pop up. That is my intent as per the following subroutine. However the MsgBox comes up TWICE instead of ONCE. I don't know why.

-------------------------------------------------------------------
Private Sub Form_BeforeUpdate(Cancel As Integer)
   Dim strLowCase As String
   Dim strUpperCaseLN As String
   Dim strUpperCaseFN As String
   Dim str_sql As String
   Dim rsList As ADODB.Recordset
   Dim cn As ADODB.Connection
   Set cn = CurrentProject.Connection
   Set rsList = New ADODB.Recordset
   
   rsList.Open "SELECT * from tblPSEmailAll where EMAILADD = '" & Me.EMAILADD & "'", cn, 2, 2
 
   If rsList.EOF Then
      MsgBox "Invalid Email Address, Press ESC to back out update", vbOKOnly, ""
      Me.EMAILADD.SetFocus
      Cancel = True
      Exit Sub
   Else
       
   End If
   
   
   rsList.Close
   rsList.Open "SELECT * from tblPSEmailAll where BRANCH = '" & Me.BRANCH & "'", cn, 2, 2
   
   If rsList.EOF Then
      Me.BRANCH.SetFocus
      Cancel = True
      MsgBox "Invalid Branch, Press ESC to back out update", vbOKOnly, ""
   Else
      Me.BRANCH = Format(Me.BRANCH, "000")
   End If
End Sub
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros