Solved

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

Posted on 2013-01-24
11
351 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
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.

932 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

11 Experts available now in Live!

Get 1:1 Help Now