Access VBA cannot find "variable"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • accesstruggle
    New Member
    • Mar 2009
    • 2

    Access VBA cannot find "variable"

    Hello,
    I am having trouble with my database in Access. The problem lies in my report. I have created a report based off a query. The query contains all values that I'll need for my report- some will be directly on the report in text boxes, etc and others will be needed for calculations only and so are not directly on the report. My problem is when I'm writing the code for my text box "TriagePerc ent" which should, based on the AuditNum (pk) calculate the triage percent for each audit. The triage percent is basically checking to see if fields are true or false. If they're true, I'm adding one to my counter. At the end, I'm going to divide the counter by the number of items it counted (which will be hard-coded, never going to change) to get the Triage percent. Then I want that value to be shown in the text box on my report. Right now to simplify things, I'm just trying to get the counter value to display. I have spent hours trying to figure this out, I'm new to Access and VBA but have experience in coding in Java. I'm not sure if I put this under the correct Event, that's been something that's really difficult for me to determine.
    Here's the shortened, tester version of VBA:
    Code:
    Private Sub TriagePercent_BeforeUpdate(Cancel As Integer)
        Dim numYes As Integer
        numYes = 0
        If Me.TriagNum.Value = True Then
            numYes = numYes + 1
        End If
        If Me.PulmStatus.Value = True Then
            numYes = numYes + 1
       End If
        Me.TriagePercentLabel.Caption = numYes
    End Sub
    Nothing shows up at all, and when I try to compile the code, it says "method or data member not found".
    Help, please? I feel like this should be very very simple coding but it's turning out to be difficult for me.
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    Add a field to your query with

    myFieldAsNumber : iif([myField] = 'True', 1, 0)


    Then, stick a control in a header/footer that is

    =Sum([myFieldAsNumber])


    I'm not sure what part of your code the error is related to, but that event wouldn't normally be triggered on a report.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      You've done a pretty good job of laying out your question but there are a couple of issues that could be clarified :
      1. Which line of the code does the error get reported on?
      2. Is this a report or a form? I don't believe there is an Before Update event for a report or any of its controls.

      Comment

      • accesstruggle
        New Member
        • Mar 2009
        • 2

        #4
        NeoPa, the error is triggered on line 4, If Me.TriagNum.Val ue = True Then .
        If I comment out that line, the error still occurs, but on line 7, If Me.PulmStatus.V alue = True Then . This is a report, TriagePercent is a text box. The report is not called TriagePercent, so no confusion there. As far as I know, there is a Before Update event since it appears in my program as a possible selection choice... ?

        ChipR, I tried your suggestion but then realized it's not really what I'm looking for. I need a list of all of the audits, sorted by therapist, with each audit having these values. So, as far as I know, I can't put the sum in the header/footer. I really need it to be in the detail section of the report with all of my other calculations.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          • Reports do not have a BeforeUpdate() Event
          • I'm having a little trouble understanding this one, but is something like this what you are looking for as far as an Aggegate Total per Audit?
            Code:
            DCount("*", "qryAudits", "[AuditNum] = <VALUE> And [TriagNum] = True") + _
            DCount("*", "qryAudits", "[AuditNum] = <VALUE> And [PulmStatus] = True")

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            Originally posted by accesstruggle
            NeoPa, the error is triggered on line 4, If Me.TriagNum.Val ue = True Then .
            If I comment out that line, the error still occurs, but on line 7, If Me.PulmStatus.V alue = True Then . This is a report, TriagePercent is a text box. The report is not called TriagePercent, so no confusion there. As far as I know, there is a Before Update event since it appears in my program as a possible selection choice... ?
            Very curious.

            I've looked and cannot find any circumstances where a TextBox control on a Report has any events at all, and nothing on a report has a BeforeUpdate event as far as I can see.

            Can you explain why there appears to be one available to you in your project?

            Comment

            Working...