Solved

Access Can't go to specified record on data. Validation

Posted on 2013-01-24
11
341 Views
Last Modified: 2013-01-24
Hi, I have the following code in my firms before update event:

If isnull(me.date) then
Msgbox "date field cannot be blank"
Date.setfocus
Cancel=true

The code works ie when the date field is left blank the user is prompted with the message box. The problem is after you click on ok on the defined error to accept it, you then get a ms access error: "you can't go to the specified record".  

How can I get access not to display this message?
0
Comment
Question by:jaykh
  • 4
  • 4
  • 3
11 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38814566
in the design view of the table where your form is bound to,
see if the [Date] field is a required field..

if it is a required field, then you need to enter some values to it..

if you don't want this, remove required setting of fields..  

btw, [Date} as a name of a field is not a good idea.. Date is a reserved word in access.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38814567
Do you have data validation defined in the underlying table's design, such as not allowing blanks in the table?

If you want to use your Before Update code, you may need to remove any table-level validation to avoid getting duplicate messages.
0
 

Author Comment

by:jaykh
ID: 38814586
I don't have any validation rules on the table design, and required us set to no for all the fields
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38814607
<<
and required us set to no for all the fields
>>

So you were required to set allow blanks/nulls to 'no' for all fields?

That is why you are getting two messages...

If you want to use the Before Update code, you need to change that setting in your table so that the table design allows blanks/nulls  -- and handle them through code like your Before Update event code.

OR as many regulars here do, use the table settings INSTEAD of your Before Update code.
0
 

Author Comment

by:jaykh
ID: 38814632
I've set the required property to yes, still get the message
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38814644
<ou then get a ms access error: "you can't go to the specified record".  >

are you trying to move to another or new record..?

before you can do that, you need to
* save the current record
      me.dirty=false    'will do that

* cancel the changes
  me.undo   'will do that
0
 

Author Comment

by:jaykh
ID: 38814694
All I am trying to do is when a user has entered details into a form and then click on add, of they haven't completed the date field then they will be presented with a warning box that they must enter a date

Though I have got this after they click on to the error message they are getting another message saying that they can't go to specified record. If I click on ok I Canmore and add a date to the form without losing any of the data they have entered into the previous field.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
ID: 38814719
post the codes behind the button ADD
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 250 total points
ID: 38814736
Try placing the validation code behind the Add button, before actually adding the new record:

Private Sub cmdAdd_Click()

' Do the validation check first...

If isnull(me.date) then
      Msgbox "date field cannot be blank"
      Me.Date.setfocus
      Exit Sub    '<---- Change the Cancel to Exit Sub
end if

' ***  Place your existing add button code here, after the validation check

End Sub

Open in new window

0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 38814773
;-)
0
 

Author Comment

by:jaykh
ID: 38814802
Fabulous thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server views 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 Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

757 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

19 Experts available now in Live!

Get 1:1 Help Now