473,387 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using subtotal pulled from subform in calculations on main form

I have a subform that totals a subtotal in the form footer. It works fine. I then pull that value onto the main form into a textbox called Subtotal2 by setting the control source =OrderSubform.Form!Subtotal and it seems to work fine.

When I try to reference the Subtotal2 text box to perform calculations on it it doesn't work. For instance when in vba I set Me.tax = Me.Subtotal2 * TaxRate I get zero. I tried just saying Me.tax = Me.Subtotal2 to see if thats where the problem is and it is still zero. If I change it to Me.tax = 50 it comes out as 50 so I know the code is executing. Any ideas? The Subtotal2 box displays the correct subtotal but the vba code seems to think it is zero.
Oct 21 '09 #1
12 4261
Does anyone have any ideas? I'm at an impass until I figure this out and I've tried everything I can think of. I tried requeries, refreshes, afterupdates etc but nothing seems to work.
Oct 21 '09 #2
NeoPa
32,556 Expert Mod 16PB
Nothing obvious springs to mind. May I suggest posting your database as an attachment. I rarely suggest this, but your problem is intriguing and I can only imagine determining the problem with direct, hands-on, access to the project.

When attaching your work please follow the following steps first :
  1. Remove anything not relevant to the problem. This is not necessary in all circumstances but some databases can be very bulky and some things do not effect the actual problem at all.
  2. Likewise, not entirely necessary in all cases, but consider saving your database in a version not later than 2003 as many of our experts don't use Access 2007. Largely they don't want to, but some also don't have access to it. Personally I will wait until I'm forced to before using it.
  3. If you've done anything in steps 1 or 2 then make sure that the problem you're experiencing is still evident in the updated version.
  4. Compact the database.
  5. Compress the database into a ZIP file.
  6. When posting, scroll down the page and select Manage Attachments (Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.) and add this new ZIP file.

While I'm here I will just mention that bumping a thread before at least 24 hours has passed is considered impatient and not too well appreciated. I can see you're new so I won't worry about it now, but please remember if you intend to continue to use the service. A full list of our rules can be found under the Help link on every page.

Welcome to Bytes!
Oct 21 '09 #3
Thank you for the reply. I deleted everything that wasn't relevant. The form in question is OrderForm. When you open it, at the top are some dropdowns for dept, item, size etc. Choose something to buy and press add item, it then is added to the transactions table and appears in the subform below. The subtotal appears under the subform in a textbox called Subtotal2 and updates correctly. In the VBA code, the relevant code is in the Private Sub AddButton_Click() section. After the addbutton is pressed, the subform is requeried and then I try setting Me.Total = Me.Subtotal2 which doesn't work. I simplified this by taking out the tax line, but the root problem is the same.
I also tried adding a Private Sub Subtotal2_AfterUpdate() section with the Me.Total = Me.Subtotal2 code but that doesn't work either.

I am using Access 2003
Attached Files
File Type: zip register.zip (57.0 KB, 220 views)
Oct 22 '09 #4
NeoPa
32,556 Expert Mod 16PB
It looks like you've made a fine job of this. I'm impressed.

I can't start now to look at this though as time is getting on (01:27) and I need to wind up for the night. I'll keep it linked to look at again tomorrow though.
Oct 22 '09 #5
Thank you for taking the time and for the compliment.
Oct 22 '09 #6
NeoPa
32,556 Expert Mod 16PB
It complained of a Missing reference first time, but it was obviously 2007 and the reference to the Outlook library hadn't been updated. I worked it out though so I have it working now. Just looking at it so I should post again soon.
Oct 23 '09 #7
NeoPa
32,556 Expert Mod 16PB
Ah. The control is never updated ;) The event is never triggered as the contents of the cell doesn't change as such. The value does, but the formula doesn't. Check out the Help system for the AfterUpdate event (from the help for the property click on the link to the event).

It explains that changes made by VBA do not trigger the event. It should really explain it such that only manual updates by the operator trigger the event.

I hope this clarifies the issue for you.
Oct 23 '09 #8
I suspected the Subtotal2_AfterUpdate() wasn't triggering, but the AddButton_Click() event definately is and the Me.Total = Me.Subtotal2 code is there as well. It definately executes because when I substitute a value, such as 50 so that it reads Me.Total = 50 the Total textbox changes to 50. But when it is set to Me.Total = Me.Subtotal2 and the Subtotal2 textbox is 50 the Total textbox remains zero.


Edited typo please reread as it made no sense before I fixed it.
Oct 23 '09 #9
Is it possible that the code is executing the Me.Total = Me.Subtotal2 before the subform has completed updating on the previous line? If so, is there a way to delay that line from executing a few milliseconds? I think this may be happening because when I add a second button that executes VBA code that sets Me.Total = Me.Subtotal2 and press that button after pressing the AddButton, it updates correctly, presumably after the subform has had enough time to requery. This is a combersome fix though, requiring the user to click two buttons to perform one task. I would much rather have a way to delay the execution of the Me.Total = Me.Subtotal2 line in the AddButton_Click() event code.
Oct 23 '09 #10
I found how to delay the code from executing and delayed it .1 seconds and that fixed it. Thanks for helping out.
Oct 23 '09 #11
NeoPa
32,556 Expert Mod 16PB
@etmanage
That all sounds very weird and unexpected. I overlooked the rest of your post earlier I'm afraid. I'll look more deeply into that. It may not be as strange as a delay that's needed.
Oct 23 '09 #12
NeoPa
32,556 Expert Mod 16PB
It looks as you say like the .Requery method from the previous line returns control before all the associated items have been updated.

I would think waiting for a second would be too long though. I've played with this quite a bit and checked the Help system (can be quite useful although can also be frustrating at times) but it doesn't seem this is included anywhere. I wanted to find a way to check that the data was available before proceeding, but nothing I tried worked.

Eventually I thought the best way (if it doesn't have problems for you, unrelated to what we've discussed) would be to set the .ControlSource of [Total] to =[Subtotal2]. I hope this is some help. I admit to being stumped on finding a logical way for the assignment to work in VBA.
Oct 23 '09 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Txsg8r | last post by:
I have a main form with a subform on it. When I click a button on the main form, I perform some calculations on data contained in the subform's table (all related records actually). However,...
3
by: Charlene | last post by:
I have an Invoice/Invoice Details form/subform. In the page footer of the Invoice Details subform I have a textbox with the control source set to =Sum(). I then pull this value into the main form...
1
by: phaddock4 | last post by:
Being fairly inexperienced at Access 2000, i've been reading many posts here for the last several days, and testing myself to find the best approach to do the following in A2K: SET UP: I have...
3
by: google | last post by:
I'm developing an application for use within my company in Access 2003. I'm new to '03, the application I did for my former employer was in '97. The two applications have similar functionality...
3
by: panwala_bhavesh | last post by:
I have a subform in continuous form style that I use to populate 3 fields (textboxes) on my main form with a double-click of the key-field textbox of the sub: Private Sub...
0
by: robert.waters | last post by:
Hello, Say that there is a database for client information; there is a main form that displays the client's name, and this form has one or more subforms that display different types of...
5
by: vsteshenko | last post by:
Hello, This is my second post to the any usernet group and the first one was posted to the wrong one. I am currently working on creating an order form for sales associates at my work to be used...
3
by: xian2 | last post by:
Hi All, I am trying to create a subtotal text box much like the one in the orders form of the northwind database where you have a subtotal text box in the footer of the subform and then have that...
1
by: lawton | last post by:
Source: this is an access 2003 question My knowledge level: reading books, internet, and trial & error; no formal training I'm trying to get a running sum of what's filtered in a subform which is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.