?
Solved

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

Posted on 2013-01-24
11
Medium Priority
?
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
11 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1000 total points
ID: 38814719
post the codes behind the button ADD
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 1000 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38814773
;-)
0
 

Author Comment

by:jaykh
ID: 38814802
Fabulous thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 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