Solved

HOW TO ELIMINATE ERROR MESSAGE WHEN CLICK EITHER “CLOSE, BACK OR NEXT”.

Posted on 2010-08-15
7
488 Views
Last Modified: 2013-11-28
PROBLEM CODE

Problem code on the BEFORE UPDATE EVENT ON FORM “frmAHA_VER1”


Sub Form_BeforeUpdate(Cancel As Integer)

If Nz(DLookup("AHATitle", "3-tblAHA_VER1", "AHATitle='" & Me.AHATitle & "'"), "") <> "" Then
  MsgBox "The AHA Title you entered is a duplicate. To continue, click the BACK BUTTON and enter a unique AHA Title. If you still have questions or problems please contact the CSSC office for support at: Phone: 630-566-9010 - Email: csscservice@comcast.net.", vbOKOnly
  Cancel = True
End If
End Sub


DESCRIPTION

Chnage or add any information to any of the FIELDS on either the "AHA Details tab" or the "Dirty Dozen tab" causes the message to be displayed.


RECREATE ERROR MESSAGE

1 LOG INTO APPLICATION
2. CLICK THE EDIT AHA BUTTON
3. SELECT ANY AHA
4. WHEN YOU GET TO THE FORM “frmAHA_VER1” edit, change or add information to any field on either tab. Then click either Close, Back or Next.
The error message will then display.


ErrorMessage-8-15-2010.jpg
TEST-8-15-2010-AHA-Builder-2010-.zip
0
Comment
Question by:cssc1
7 Comments
 
LVL 10

Expert Comment

by:t_hungate
ID: 33442191
CSSC

I have looked at this a bit, and the form that is giving you this problem, is meant to update or edit, a  record that is currently in the recordset, correct?

If so you are issue is that your code is just looking to see if the title matches any title already in the table.  When that is found to be true you are presented the the error message.  The problem is, you are editing a record that you know to be in the table, and there for should not be running this IF.  

Now I think you may want to check and make sure that they have not changed the title while they were editing the form, and I would warn them that changing the title will cause them to loose any changes that were made, or something to that effect.  I would also, check to ensure that the title is not blank, before you allow them to proceed to the next form.

So long story short, you do not need this code here, as the title is being carried over form the first form, and you will get a true return on your IF statement every time.  I have commented it out and made some test edits to the data, and the forms all seem to work as they appear to be designed to.

TLH
0
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 33442260
If this is an existing record, then your DLookup will find the same record that you are editing.  You need to look for records with a matching title EXCLUDING the current record.
Does your table have a primary key?  Let's assume you have an autonumber PK named AHI_id.  You can then use this code:
If Nz(DLookup("AHATitle", "3-tblAHA_VER1", "AHATitle='" & Me.AHATitle & "'"), 0) <> Me.AHI_id Then
--
Graham
0
 
LVL 20

Assisted Solution

by:GrahamMandeno
GrahamMandeno earned 500 total points
ID: 33442263
Oops - sorry - copy/paste error...
If Nz(DLookup("AHA_id", "3-tblAHA_VER1", "AHATitle='" & Me.AHATitle & "'"), 0) <> Me.AHI_id Then
--
Graham
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:cssc1
ID: 33442517
GrahamMandeno:
  Code won't compile.
See attached image for error message
seeError-8-15-2010.jpg
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33443236
Make a note, this message means that it cannot find that Field or control.
So substitute it with the name of the field that actually holds this ID
0
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 500 total points
ID: 33444205
@cssc1:
Note that I said: <<Let's assume you have an autonumber PK named AHI_id.>>
Does your table have such a primary key field?  If not, then of course the code will not work.
Make sure that the field name in your code matches the name of the primary key in your table (note that it appears twice in that line) and also that it is included in the RecordSource of your form.
--
Graham
0
 

Author Closing Comment

by:cssc1
ID: 33444229
Thanks!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now