Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-08-15
7
Medium Priority
?
498 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 2000 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

886 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