By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,372 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Comparing Calculated fields on seperate forms

P: 78
I have two forms [fsubinputvoltage] and [fsubelectronic] that have unbound calculated fields. Thes are both subforms to [frmHeaderMaster]. The field on [fsubinputvoltage] is [calcAvailPower] and field for [fsubelectronic] is [calcOutputPower]. On [calcOutputPower] being dirty or updated I need a message box if [calcOutputPower] is greater than [calcAvailPower]. Can someone help?
Jun 22 '07 #1
Share this Question
Share on Google+
13 Replies


BradHodge
Expert 100+
P: 166
I believe that you would just need to use an AfterUpdate Event similar to this...

Expand|Select|Wrap|Line Numbers
  1. Private Sub calcOutputPower_AfterUpdate() 
  2.     If calcOutputPower > Forms![frmHeaderMaster]![fsubinputvoltage].Form![calcAvailPower] Then
  3.     MsgBox ("It's Greater!")
  4.     End If
  5. End Sub
Good Luck,
Brad.
Jun 22 '07 #2

P: 78
I believe that you would just need to use an AfterUpdate Event similar to this...

Expand|Select|Wrap|Line Numbers
  1. Private Sub calcOutputPower_AfterUpdate() 
  2.     If calcOutputPower > Forms![frmHeaderMaster]![fsubinputvoltage].Form![calcAvailPower] Then
  3.     MsgBox ("It's Greater!")
  4.     End If
  5. End Sub
Good Luck,
Brad.
Getting #Name?.... Figured out this has something to do with my formula used to calculate the calcOutputPower.....will get back to you when I get this figured out.

AO3
Jun 22 '07 #3

P: 78
Got other problem fixed.. Okay I have it semi working. It will work if I place a Command button and click on it using the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command31_Click()
  2.     If Me.txtOutputPOwer.Value > Forms![frmHeaderMaster]![fsubInputVoltage].Form![calcAvailPower] Then
  3.     MsgBox ("It's Greater!")
  4.     End If
  5.  
  6. End Sub
However, if I use the following code... Nothing happens....

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtOutputPOwer_AfterUpdate()
  2.     If Me.txtOutputPOwer.Value > Forms![frmHeaderMaster]![fsubInputVoltage].Form![calcAvailPower] Then
  3.     MsgBox ("It's Greater!")
  4.     End If
  5. End Sub
This is a subform on a tabcontrol.
Jun 22 '07 #4

BradHodge
Expert 100+
P: 166
You got me. Since you had it on a tab control, I placed mine on a tab control and tried it again in an AfterUpdate event without changing the code at all. Worked like a charm.

Oh well... as long as it's working I guess :)
Jun 22 '07 #5

P: 78
no, I need to figure out why it isn't working.... Management is pretty intent on it working after update...
Jun 22 '07 #6

BradHodge
Expert 100+
P: 166
What version of Access are you using?
Jun 22 '07 #7

P: 78
Access 2003 but saving in 2000 format. Also this is written as an Access project....if that makes any difference.
Jun 22 '07 #8

BradHodge
Expert 100+
P: 166
Can you post your code for frmHeaderMaster, and the 2 subforms?
Jun 22 '07 #9

P: 78
yep

frmHeaderMaster

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Command43_Click()
  4. On Error GoTo Err_Command43_Click
  5.  
  6.     Dim stDocName As String
  7.  
  8.     stDocName = "Application Inquiry Form"
  9.     DoCmd.SendObject acReport, stDocName, "SnapshotFormat(*.snp)", _
  10.   "DELETED", "", "", "This is a test.", "", False, ""
  11.  
  12.  
  13. Exit_Command43_Click:
  14.     Exit Sub
  15.  
  16. Err_Command43_Click:
  17.     MsgBox Err.Description
  18.     Resume Exit_Command43_Click
  19.  
  20. End Sub
  21. Private Sub Command45_Click()
  22. On Error GoTo Err_Command45_Click
  23.  
  24.  
  25.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  26.  
  27. Exit_Command45_Click:
  28.     Exit Sub
  29.  
  30. Err_Command45_Click:
  31.     MsgBox Err.Description
  32.     Resume Exit_Command45_Click
  33.  
  34. End Sub
  35. Private Sub Command46_Click()
  36. On Error GoTo Err_Command46_Click
  37.  
  38.  
  39.     DoCmd.GoToRecord , , acNewRec
  40.  
  41. Exit_Command46_Click:
  42.     Exit Sub
  43.  
  44. Err_Command46_Click:
  45.     MsgBox Err.Description
  46.     Resume Exit_Command46_Click
  47.  
  48. End Sub
  49. Private Sub Command47_Click()
  50. On Error GoTo Err_Command47_Click
  51.  
  52.     Dim stDocName As String
  53.  
  54.     stDocName = "Application Inquiry Form"
  55.     DoCmd.OpenReport stDocName, acPreview, "", "[CrNo]=[Forms]![frmHeaderMaster]![CrNo]"
  56.  
  57. Exit_Command47_Click:
  58.     Exit Sub
  59.  
  60. Err_Command47_Click:
  61.     MsgBox Err.Description
  62.     Resume Exit_Command47_Click
  63.  
  64. End Sub
fsubelectronic
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Private Sub Command31_Click()
  3.     If Me.txtOutputPOwer.Value > Forms![frmHeaderMaster]![fsubInputVoltage].Form![calcAvailPower] Then
  4.     MsgBox ("It's Greater!")
  5.     End If
  6.  
  7. End Sub
  8.  
  9. Private Sub txtOutputPOwer_AfterUpdate()
  10.     If Me.txtOutputPOwer.Value > Forms![frmHeaderMaster]![fsubInputVoltage].Form![calcAvailPower] Then
  11.     MsgBox ("It's Greater!")
  12.     End If
  13. End Sub
fsubinputvoltage has no module

txtOutputPOwer
Expand|Select|Wrap|Line Numbers
  1. =IIf([CoUom]="Oz.-In.",([ContRpm]*[ContTorq]/1352), IIf([CoUom]="Lb.-Ft.",([ContRpm]*([ContTorq]*192)/1352), IIf([CoUom]="Nm",([ContRpm]*([ContTorq]*141.6116)/1352), IIf([CoUom]="mNm",([ContRpm]*([ContTorq]*0.1416116)/1352))))) 
calcAvailPower
Expand|Select|Wrap|Line Numbers
  1.  =[BusVolt]*[DrvCurLim]
Jun 22 '07 #10

BradHodge
Expert 100+
P: 166
The code for txtOutputPOwer...

=IIf([CoUom]="Oz.-In.",([ContRpm]*[ContTorq]/1352), IIf([CoUom]="Lb.-Ft.",([ContRpm]*([ContTorq]*192)/1352), IIf([CoUom]="Nm",([ContRpm]*([ContTorq]*141.6116)/1352), IIf([CoUom]="mNm",([ContRpm]*([ContTorq]*0.1416116)/1352)))))
What event is that in?... AfterUpdate?
Jun 22 '07 #11

P: 78
No that is the control source for that control. Sorry took so long for a reply, but took the weekend away from all of this and tossed back a few cold ones. I also have placed a Break point on the Line :
Expand|Select|Wrap|Line Numbers
  1. If Me.txtOutputPOwer.Value > Forms![frmHeaderMaster]![fsubInputVoltage].Form![calcAvailPower] Then
and no break happens so for some reason it never even sees the code.
Jun 25 '07 #12

BradHodge
Expert 100+
P: 166
I'm not sure. This may be grasping at straws, but I wonder if you stored the two calculated results as variables and then compared the variables?

Brad.
Jun 25 '07 #13

P: 78
I got it to work by changing how I control the visible function and forcing the entry person to hit a next button to make the next tab visible.

Here is code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnmechReq_Click()
  2. Dim intAnswer As Integer
  3.  If Forms![frmHeaderMaster]![fsubelectronic].Form![txtOutputPOwer].Value > Forms![frmHeaderMaster]![fsubInputVoltage].Form![calcAvailPower] Then
  4.     intAnswer = MsgBox("You Have Violated the Laws of Physics!!" & vbCrLf & "Please adjust Input Voltage or Continuous RPM / Torque." & _
  5.     vbCrLf & "Click Yes to Adjust Input Power. Click No to Adjust Output Voltage", vbExclamation + vbYesNo, "Adjust Input Voltage")
  6.         If intAnswer = vbYes Then
  7.         Me.Input_Power.SetFocus
  8.                End If
  9. Else
  10. If Forms![frmHeaderMaster]![fsubelectronic].Form![txtOutputPOwer].Value <= Forms![frmHeaderMaster]![fsubInputVoltage].Form![calcAvailPower] Then
  11.         MsgBox ("Available Voltage Meets Requirements. Proceed to next tab")
  12.         Me.Mechanical_Design.SetFocus
  13. End If
  14. Me.Application_Description.Visible = True
  15. Me.Input_Power.Visible = True
  16. Me.Application_Requirements.Visible = True
  17. Me.Mechanical_Design.Visible = True
  18. Me.Options.Visible = False
  19. Me.Competetive_Info.Visible = False
  20. Me.Potential.Visible = False
  21. End If
  22. End Sub
Jun 25 '07 #14

Post your reply

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