Run-time error 2115 when changing a dtpicker's value in a tab cont

J

Josh

I'm developing a form that uses a listbox to display records. Record data is
displayed in a variety of fields, which are organized into tabs. The user
clicks on a record in the listbox to populate the form fields.

One of the tabs has some dtpicker fields for choosing dates. I've learned
that a dtpicker field must be visible on the form in order for its value to
be changed. This means I have to switch to the "Schedule" tab before I can
try populating the dtpicker fields.

Here is the code in the listbox's OnClick event which populates one of the
dtpickers named "dtpOriginal":

Dim selectedTab As Integer
selectedTab = Me.TabCtl0.Value 'Store the current tab

Me.TabCtl0.Value = 1 'Switch to the Schedule tab
Me.dtpOriginal.SetFocus 'See my note below
Me.dtpOriginal = dateOriginal 'Fill the dtpicker with some date
Me.TabCtl0.Value = selectedTab 'Go back to original tab

When the last line in that snippet executes, I get a run-time error 2115:

"The macro or function set to the BeforeUpdate or ValidationRule property
for this field is preventing Microsoft Access from saving the data in the
field."

Since the error occurs when I try to switch tabs, I assume it's TabCtl0's
BeforeUpdate or ValidationRule properties it's talking about, but the tab
control object has no such properties. Neither does the dtpicker object. In
fact, I'm quite certain none of the controls on my form have BeforeUpdate or
ValidationRule properties set. So does anyone know how this error can occur
when the situation it describes doesn't even exist in my form?

Note: In my code above, I set the form's focus to the dtpicker before I set
its value. If I don't do this, and then I end up filling the dtpicker with
NULL, the focus freezes on the listbox (where focus is when the user clicks
on a record), and clicking on any control on the form is interpreted as a
listbox_Click event. I have no clue why it does that, but sample dtpicker
code I've seen on the web uses this pre-focusing method, so I've stuck with
it to avoid headaches.
 
J

Josh

And here's something I just noticed: the runtime error does not occur if the
Schedule tab was already opened. Only if some other tab was open beforehand
does the error occur.
 

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