Calculate a text box from two other text boxes (1 Viewer)

hilian

Episodic User
Local time
Today, 03:04
Joined
May 17, 2012
Messages
130
I’m trying to have a text box display the result of a calculation based on two other text boxes. The text box, txtIntptotal, should show the result of the contents of txtIntpHours multiplied by the contents of txtIntpRate. I used the following code, in the After Update property for txtIntpHours, which worked on another form.

Private Sub txtIntpHours_AfterUpdate()
Me.txtIntpTotal = Me.txtIntpHours * Me.txtIntpRate
End Sub

When I enter a value txtIntpRate and then in txtIntpHours, I get the following error message (the db is called OPTAReports):

The expression you entered as the event property setting produced the following problem while OPTAReports was communicating with the OLE server or ActiveXControl.
*The expression may not result in the name of a user-defined function, or [Event procedure],
*There may have been an error in evaluating the function, event, or macro.

Can anyone see where I’m going wrong?

Thanks,

Henry
 
Last edited:

JHB

Have been here a while
Local time
Today, 12:04
Joined
Jun 17, 2012
Messages
7,732
Try to "Compile" you code.
 

hilian

Episodic User
Local time
Today, 03:04
Joined
May 17, 2012
Messages
130
I've never compiled code before. How do you do that?
 

NeutronFlux

Registered User.
Local time
Today, 06:04
Joined
Aug 20, 2012
Messages
78
In your VBA Editor, on the top menu, choose "Debug". The first drop-down item should be "Compile ".
 

khodr

Experts still Learn
Local time
Today, 13:04
Joined
Dec 3, 2012
Messages
112
Check the combo boxes format
As the rate combo box should be currency and the hours combo box should be numbers and the total combo box should be currency also the default value for each combo box should be (0) if you set the proper format for each combo bos then it should work, because Access has to understand that these combo boxes is able to be calculated mathmatically as if he dont understand that the combo boxes are numbers and currencies then Access cannot calculate it.
 

hilian

Episodic User
Local time
Today, 03:04
Joined
May 17, 2012
Messages
130
Thanks, Khodr,

Rate, Hours and Total are text boxes. that may or may not make a difference. I didn't have a format set. I set the formats and tried again, but I still get the error message I got to begin with:

The expression you entered as the event property setting produced the following problem while OPTAReports was communicating with the OLE server or ActiveXControl.
*The expression may not result in the name of a user-defined function, or [Event procedure],
*There may have been an error in evaluating the function, event, or macro.

The thing that's so frustrating is that I have been able to make this code work before. the difference is that originally the form was in form view. Now it's a subform in Datasheet view. Should that make a difference?
 

khodr

Experts still Learn
Local time
Today, 13:04
Joined
Dec 3, 2012
Messages
112
Nope it shouldn't make any difference because codes work in both
Can you kindly attach you form in here maybe I can test it
 

hilian

Episodic User
Local time
Today, 03:04
Joined
May 17, 2012
Messages
130
I am uploading a sanitized version of the db. Thanks for looking it over. I'll check tomorrow morning.

Henry
 

Attachments

  • OPTA Reports Interp.zip
    823.8 KB · Views: 77

khodr

Experts still Learn
Local time
Today, 13:04
Joined
Dec 3, 2012
Messages
112
Resolved,
Check the attached DataBase, I hope that is what you are looking for.
Regards.
:)
 

Attachments

  • OPTA Reports Interp.zip
    813 KB · Views: 79

hilian

Episodic User
Local time
Today, 03:04
Joined
May 17, 2012
Messages
130
Khodr,

thanks you so much for your help.

I checked what you did, and it worked. Great!

But! The way the data entry works is that the rate is filled in automatically when the user selects a language on the parent form. If the code is in the rate text box, there won't be anything in the hours text box to multiply by. Also, it makes no sense that the same code worked from the rate text box but not from the hours text box.

When I pasted the code in the rate text box on the original copy, I got the same error message. There's evidently something in the original db that's causing some interference, but I don't know where to look for it. do you have any insights?

Henry
 

khodr

Experts still Learn
Local time
Today, 13:04
Joined
Dec 3, 2012
Messages
112
Hi,
if you are using windows 7 maybe you can use snipping tool to snap shot some images for your errors, and upload it here then I can see it and I could figure out what is exactly happening
Regards.
 

hilian

Episodic User
Local time
Today, 03:04
Joined
May 17, 2012
Messages
130
Unfortunately, I'm using XP. I can do a screen shot of the error message, but I quoted it a few posts ago, and I don't think the actual message is different. What I'm thinking of doing is rebuilding the db starting with the file you returned to me, which works, or possibly with a new Access file. The code seems correct, but something is keeping it from working. Does that sound like a way to go?
 

khodr

Experts still Learn
Local time
Today, 13:04
Joined
Dec 3, 2012
Messages
112
No you don't need to start again from scratch I know it could be hard but escaping from the problem doesn't solve it what would you do if you face it again, you can maybe rebuild the form again, save as your current form and try and rebuild the form again link the data properly, data must be structured good and linked in a smooth manner like:
For me I don't like to link directly with tables I always build queries and link my form to queries or I use a recordset in your case it's easier you build a query from your table and re-link your form controls. Give it a try
 

Users who are viewing this thread

Top Bottom