Solved

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

Posted on 2013-01-24
11
379 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

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

Expert Comment

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

Author Comment

by:jaykh
ID: 38814802
Fabulous thanks
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

733 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