Access Helping Me Too Much

R

Ripper

I am using the following code to check for duplicate values in a required
field.
Dim strCriteria As String
strCriteria = "StuID =" & Me.StuID
If Not IsNull(DLookup("StuID", "tblStudents", strCriteria)) Then
MsgBox "This Student ID was already used", vbOKOnly, "Student ID Used."
Cancel = True

I get the message as normal, but the Access has to jump in with another
message box that says..
The value in the field or record violates the validation for the record
of field.
For Example, you may have changed a validation rule without verifying
wheter...
Click Undo on the Edit menu to restore the previous value, or enter....

How can I stop access from being so helpful? I don't want this message box.
I made my own.
 
F

Fred

I think that 99% of Microsoft software questions start with either

"How can I stop it from..........?"

or

"_____ was working fine, and then Microsoft broke it by............."


You'd think they'd notice.
 
B

BruceM

In such cases you need to specify the event in which this code is located.
If this is the Before Update event of a control (or form) it should work OK,
except you could try adding:
Me.SomeControl.Undo as a new line before Cancel = True
where SomeControl is the name of the control containing the value to be
tested.

If it is something other than a Before Update event, that could be the
problem. Does the code compile correctly?
 
R

Ripper

Compiles fine. This really makes me mad. Undo doesn't stop the annoying
popup. I went back to the table and took off required, but now it the popup
works, but I can add information in other fields and leave StuID blank and I
can submit the record. I guess I could put an IsNull clause in the
BeforeUpdate of the form. Would that work?
--
Thanks As Always
Rip


BruceM said:
In such cases you need to specify the event in which this code is located.
If this is the Before Update event of a control (or form) it should work OK,
except you could try adding:
Me.SomeControl.Undo as a new line before Cancel = True
where SomeControl is the name of the control containing the value to be
tested.

If it is something other than a Before Update event, that could be the
problem. Does the code compile correctly?
 
B

BruceM

I wrote: "In such cases you need to specify the event in which this code is
located." I guess I should have been more direct. In what event is the
code located?

Generally speaking you should validate in the form's Before Update event.
If you are using the control's Before Update event, try Undo as I suggested.

Ripper said:
Compiles fine. This really makes me mad. Undo doesn't stop the annoying
popup. I went back to the table and took off required, but now it the
popup
works, but I can add information in other fields and leave StuID blank and
I
can submit the record. I guess I could put an IsNull clause in the
BeforeUpdate of the form. Would that work?
 
B

BruceM

You must mean the Before Update event of the control (fields are in tables,
and don't have events). In that case, use the Me.Undo line of code before
Cancel = True as I suggested. This will "erase" whatever was entered in the
control. The SetFocus line of code will put the cursor into that text box
for another try. If the user leaves the field blank, the form's Before
Update event can catch that.

You should probably leave the field in the table as Indexed (No Duplicates),
especially if you intend to look up students from time to time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top