Me.Refresh causes error (1 Viewer)

mcescher

Busy as usual
Local time
Today, 11:39
Joined
Mar 19, 2018
Messages
28
Hi All,
Kind of a strange question.

I have a form with 10 text boxes that the user will fill in and the last two will do calculations based on the information that they entered.

So, I've added code like this for each of the entry text boxes

Code:
Private Sub txtField1_AfterUpdate()
    Me.Refresh
End Sub

That way if the user goes back to Field1 and changes the entry, the answers will update. I am checking for empty fields and those are all fine.

My problem is that one of the text fields gives me an error:

Database can't find the object 'Me.'
If 'Me' is a new macro or macro group, make sure you have saved it and that you have typed its name correctly.

But only that specific text box. Doesn't matter if they're all empty or all filled.

All the rest of the text boxes are fine. They update and don't give an error message.

What's up?
 

isladogs

MVP / VIP
Local time
Today, 16:39
Joined
Jan 14, 2017
Messages
18,186
What is the name of that text field?
Does it contain a space or special character such as % or /
 

missinglinq

AWF VIP
Local time
Today, 12:39
Joined
Jun 20, 2003
Messages
6,423
Have no idea why Access would balk and give that kind of error with

Me.Refresh

That error usually pops when you try to use Me. in the Control Source Property of a Control.

If your concern is having a calculated field be re-calculated, when one of the component fields is changed, you really should be using

Me.ReCalc

instead. Why don't you try that?

Linq ;0)>
 

JHB

Have been here a while
Local time
Today, 17:39
Joined
Jun 17, 2012
Messages
7,732
Post a printscreen of the error and the actually code, or post your database with some sample data + description to reproduce the error.
 

mcescher

Busy as usual
Local time
Today, 11:39
Joined
Mar 19, 2018
Messages
28
Found it... Sometimes it's the silly mistakes.

While I was clicking in the Properties window in Access to add the "_AfterUpdate" link, I accidentally hit Ctrl V in that box. So instead of

"[Event Procedure]"

It said

"Me.Refresh[Event Procedure]"

And Access didn't like that. :banghead::rolleyes:

Thanks to everyone for you responses,
Chris
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:39
Joined
Feb 19, 2002
Messages
42,971
Me.Refresh forces the current record to be saved before it refreshes the recordset. Therefore, it should NOT be used mid process because you end up saving incomplete records. If you have validation in the form's BeforeUpdate event (which you should), it will be executed prematurely and raise errors when it shouldn't.

Calculated values should not be stored. Do this calculation in the query and it will refresh automatically if any component field changes. If you insist on saving the calculated value (you should not. It is poor practice and leads to data anomalies), at least use the BeforeUpdate event which doesn't run until the record is being saved so all values should actually be present.
 

mcescher

Busy as usual
Local time
Today, 11:39
Joined
Mar 19, 2018
Messages
28
Yup, know all that. This is a disconnected recordset, and not storing the values. Just a simple calculator for the user to know how much material to order. They take that and make choices in another form.

Thanks,
Chris
 

Users who are viewing this thread

Top Bottom