Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-01-24
11
Medium Priority
?
408 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
Independent Software Vendors: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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