Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / June 2007

Tip: Looking for answers? Try searching our database.

Before Update

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan @BCBS - 26 Jun 2007 16:44 GMT
I'm trying to add a pop-up comment when the user enters a certain number in
the text box.
The code below I added to the text box but it does nothing.

Any suggestions.

Private Sub MEMBERNO_BeforeUpdate(Cancel As Integer)
If Me.MEMBERNO = "H23917176" Then
       MsgBox "** Please contact the fraud dept. **"
       Exit Sub
   End If
End Sub
Dennis - 26 Jun 2007 17:20 GMT
You need to put it in the after update event instead because in the before
update, the value is not in the box yet.

> I'm trying to add a pop-up comment when the user enters a certain number in
> the text box.
[quoted text clipped - 8 lines]
>     End If
> End Sub
Klatuu - 26 Jun 2007 18:20 GMT
That is not correct, Dennis.  It is in the form control (box), but not yet
updated to the form's recordset.  One thing that is missing is canceling the
event.  I would put a line
Cancel = True
just before the Msgbox line.

Run the code in debug mode to determine why it is not showing the message box.
Signature

Dave Hargis, Microsoft Access MVP

> You need to put it in the after update event instead because in the before
> update, the value is not in the box yet.
[quoted text clipped - 11 lines]
> >     End If
> > End Sub
Dan @BCBS - 26 Jun 2007 21:40 GMT
That is perfect - Thanks

One last question - I'm trying to add an "OR" statement:
If Me.MEMBERNO = "H23917176" Or "H39592261" Then

I've tried about 12 other was and I'm getting no-where..

Suggestions??

> That is not correct, Dennis.  It is in the form control (box), but not yet
> updated to the form's recordset.  One thing that is missing is canceling the
[quoted text clipped - 19 lines]
> > >     End If
> > > End Sub
Klatuu - 26 Jun 2007 21:43 GMT
Here is number 13 :)

If Me.MEMBERNO = "H23917176" Or Me.MEMBERNO "H39592261" Then

Signature

Dave Hargis, Microsoft Access MVP

> That is perfect - Thanks
>
[quoted text clipped - 28 lines]
> > > >     End If
> > > > End Sub
Dan @BCBS - 26 Jun 2007 21:55 GMT
Compile error - Suggestions for #14??

If Me.MEMBERNO = "H23917176" Or Me.MEMBERNO "H39592261" Then
Cancel = True
Else
       MsgBox "**.....

> Here is number 13 :)
>
[quoted text clipped - 32 lines]
> > > > >     End If
> > > > > End Sub
Klatuu - 26 Jun 2007 21:58 GMT
Actually, this should only be 13.1
   If Me.MEMBERNO = "H23917176" Or Me.MEMBERNO = "H39592261" Then

Oops, left out the =
Signature

Dave Hargis, Microsoft Access MVP

> Compile error - Suggestions for #14??
>
[quoted text clipped - 39 lines]
> > > > > >     End If
> > > > > > End Sub
Dan @BCBS - 26 Jun 2007 22:06 GMT
13.2
The message box appears no matter what is entered??

> Actually, this should only be 13.1
>     If Me.MEMBERNO = "H23917176" Or Me.MEMBERNO = "H39592261" Then
[quoted text clipped - 44 lines]
> > > > > > >     End If
> > > > > > > End Sub
Klatuu - 26 Jun 2007 22:09 GMT
What is the actual error?
post the entire sub or function.
Is MEMBERNO the name of a control on your form?

Signature

Dave Hargis, Microsoft Access MVP

> 13.2
> The message box appears no matter what is entered??
[quoted text clipped - 47 lines]
> > > > > > > >     End If
> > > > > > > > End Sub
Dan @BCBS - 26 Jun 2007 22:17 GMT
There is no actual error - the message pops up - but it pops up for any entry.
Yes MEMBERNO is the control on the form which is straight from the table, no
query.

Private Sub MEMBERNO_BeforeUpdate(Cancel As Integer)
If Me.MEMBERNO = "H23917176" Or Me.MEMBERNO = "H39592261" Then
Cancel = True
Else
   MsgBox "** Contact the fraud dept. ASAP **"
       Exit Sub
   End If
End Sub

> What is the actual error?
> post the entire sub or function.
[quoted text clipped - 51 lines]
> > > > > > > > >     End If
> > > > > > > > > End Sub
Klatuu - 26 Jun 2007 22:28 GMT
Okay, I see what you are saying.  The code is doing exactly what you are
telling it to do. (that's what  I hate about computers)

Private Sub MEMBERNO_BeforeUpdate(Cancel As Integer)
   If Me.MEMBERNO = "H23917176" Or Me.MEMBERNO = "H39592261" Then
       Cancel = True
   Else
       MsgBox "** Contact the fraud dept. ASAP **"
       Exit Sub
   End If
End Sub

As written, the code will throw the message box for every member number
except the two you have in the code.  If you want the message to show only
for those 2 codes, it needs to be this way:

Private Sub MEMBERNO_BeforeUpdate(Cancel As Integer)
   If Me.MEMBERNO = "H23917176" Or Me.MEMBERNO = "H39592261" Then
       Cancel = True
       MsgBox "** Contact the fraud dept. ASAP **"
   End If
End Sub

However, I would not hard code something like member numbers.  I would have
a field in the member table that would tell us to flag this as a fraud alert.
 Then if you have to add or remove member numbers, you don't have to change
the code, you only need to change the flag in the member record:

Private Sub MEMBERNO_BeforeUpdate(Cancel As Integer)
   If Nz(DLookup("[FRAUD_ALERT]", "tblMember","[MEMBERNO] = '" &
Me.MEMBERNO & "'",0)) = True Then
       Cancel = True
       MsgBox "** Contact the fraud dept. ASAP **"
   End If
End Sub

Signature

Dave Hargis, Microsoft Access MVP

> There is no actual error - the message pops up - but it pops up for any entry.
> Yes MEMBERNO is the control on the form which is straight from the table, no
> query.

Private Sub MEMBERNO_BeforeUpdate(Cancel As Integer)
> If Me.MEMBERNO = "H23917176" Or Me.MEMBERNO = "H39592261" Then
> Cancel = True
[quoted text clipped - 59 lines]
> > > > > > > > > >     End If
> > > > > > > > > > End Sub
Dan @BCBS - 26 Jun 2007 22:46 GMT
Words or Money could not express my thankfullness..
So I'll just say it - Thank you...

> Okay, I see what you are saying.  The code is doing exactly what you are
> telling it to do. (that's what  I hate about computers)
[quoted text clipped - 100 lines]
> > > > > > > > > > >     End If
> > > > > > > > > > > End Sub
Klatuu - 26 Jun 2007 22:49 GMT
I'd rather have the money :)

You are welcome, sorry about my initial confusion.
Signature

Dave Hargis, Microsoft Access MVP

> Words or Money could not express my thankfullness..
> So I'll just say it - Thank you...
[quoted text clipped - 103 lines]
> > > > > > > > > > > >     End If
> > > > > > > > > > > > End Sub
rtviper - 28 Jun 2007 22:28 GMT
YTou need to move it to "AfterUpdate" The field does nopt yet have a value.

> I'm trying to add a pop-up comment when the user enters a certain number in
> the text box.
[quoted text clipped - 8 lines]
>     End If
> End Sub
Klatuu - 28 Jun 2007 22:42 GMT
That is not correct.  If you follow tthe posts, you will see it was a logic
coding error and has been resolved.
If what you are saying were true, the Before Update event would be useless.  
The value is in the control as soon as the user enters it.  The Before Update
event does not fire until the user moves the focus to another control.
Signature

Dave Hargis, Microsoft Access MVP

> YTou need to move it to "AfterUpdate" The field does nopt yet have a value.
>
[quoted text clipped - 10 lines]
> >     End If
> > End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.