Results 1 to 3 of 3

Thread: how to reference a calculated control in the sub-form?

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Posts
    2

    Wink

    Help folks,

    I have problem in writing a code which will reference a calculated control in the sub-form.


    Private Sub fsubKpPmtVou_Exit(Cancel As Integer)
    If me.fsubKpPmtVou![Total]<> me.[Amt-Cr] Then
    Sound 3
    me.[Amt-Cr].SetFocus
    End If
    End Sub


    Private Sub fsubKpPmtVou_Enter()
    me.fsubKpPmtVou.Form.Requery
    End Sub


    Private Sub Form_Close()
    Dim db As Database, rct As Recordset, vn As String
    If me.fsubKpPmtVou![Total]<> me.[Amt-Cr] Then
    vn = me.VouNo
    Set db = CurrentDb
    Set rct = db.OpenRecordset("qryKpPmtVou")
    rct FindFirst "VouNo=vn"
    If Not rct.NoMatch Then
    rct.Delete
    End If
    End If
    End Sub

    ([Total] is an unbound control capturing the sum of a bound control "[Amt-Dr]" in the sub-form.)

    The "fsubKpPmtVou_Exit" works fine while the "Form_Close" event halts at the "If me.fsubKpPmtVou![Total]......." line.

    Any thing has gone wrong or I really cannot reference a calculated control in the form or sub-form all together. Your expertise is appreciated.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Eh, not sure what you meant with calculated control, but you can store a control in a object, control or variant variable.

    By using set you assign the reference, for instance:
    Code:
    Dim A as variant
    Set A = Controlarray(n+2)
    And to use for instance setfocus property
    Code:
    A.Setfocus
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Posts
    2
    Hi Kedaman,

    Many thanks for your help.

    I work with Access2000. I created a form in continous view and had it put into a subform control of a main form. On the form footer of the subform I created an unbound control "[Total]" with control source set "=Sum(Nz([Amt-Dr]))" and [Amt-Dr] being one of the field in the subform.

    When I run the VBA codes, the "fsubKpPmtVou_Exit" works fine while the "Form_Close" halts and gives an error message at the line

    "If Me.fsubKpPmtVou![Total]<> Me.[Amt-Cr] Then"

    The problem is why it works ok on the "fsubKpPmtVou_Exit" but the "Form_Close" when using the same referencing statement.

    Any comment and suggestions.

    Many thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width