Solved

Access 2010 Report Data From Fields On Form

Posted on 2016-07-23
12
36 Views
Last Modified: 2016-07-24
Hi Experts,
I have a Form that runs an Event to add / update data into a table.  It counts the records processed and displays the results in Counter Fields on the form.

How do I extract the data contained in the Form Counter Fields for input into a Report so the results can be printed?

Thanks,
Bob C.
0
Comment
Question by:Bob_Collison
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 41725887
<displays the results in Counter Fields on the form.>
do you mean "displays the results in more than one field/control " ?

it seems so easy when you posted your requirement, but it isn't.. give more detailed information.

for a starter, you can use TempVars collection.
set the value of a tempvar variable in Event to add / update data in the table
and use the tempvar variable as value in your report controls.
0
 

Author Comment

by:Bob_Collison
ID: 41725909
Hi Rey,
Yes I originally though this would be simple too.

The issue is there is not a Table to store the Counter Field Values in.  The Counter Fields are 'Unbound Fields' (Temporary Variables) on the Form.  Obviously I could create a Table and use it but I don't really want to do that for just this one purpose.

What I want to do is either have the Report read the data directly from the Counter Fields on the Form or have a Query read the data from the Counter Fields on the Form and supply it to the Report,

Thanks,
Bob C.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 41725929
in your report, you can create a control (textbox) and set the ControlSource of that control to:

=Forms!yourFormName!txt_CounterField
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 41725930
Or you could store the calculated result in a custom database property, which could then be displayed on a report or form.  Here is some sample code for creating and retrieving custom db properties:

Option Compare Database
Option Explicit

Private dbs As DAO.Database
Private prp As DAO.Property
Private prps As DAO.Properties


Public Sub SetProperty(strName As String, lngType As Long, _
   varValue As Variant)
'Created by Helen Feddema 2-Oct-2006
'Modified by Helen Feddema 11-Oct-2014
'Called from various procedures

On Error GoTo ErrorHandler

   'Attempt to set the specified property
   Set prps = CurrentDb.Properties
   prps(strName) = varValue

ErrorHandlerExit:
   Exit Sub

ErrorHandler:
    If Err.Number = 3270 Then
      'The property was not found; create it
      Set prp = CurrentDb.CreateProperty(Name:=strName, _
         Type:=lngType, Value:=varValue)
      CurrentDb.Properties.Append prp
      Resume Next
   Else
   MsgBox "Error No: " & Err.Number _
      & " in SetProperty procedure; " _
      & "Description: " & Err.Description
      Resume ErrorHandlerExit
   End If

End Sub

Public Function GetProperty(strName As String, strDefault As String) _
   As Variant
'Created by Helen Feddema 2-Oct-2006
'Modified by Helen Feddema 11-Oct-2014
'Called from various procedures

On Error GoTo ErrorHandler
   
   'Attempt to get the value of the specified property
   GetProperty = CurrentDb.Properties(strName).Value

ErrorHandlerExit:
   Exit Function

ErrorHandler:
   If Err.Number = 3270 Then
      'The property was not found; use default value
      GetProperty = strDefault
      Resume Next
   Else
      MsgBox "Error No: " & Err.Number _
         & " in GetProperty procedure; " _
         & "Description: " & Err.Description
      Resume ErrorHandlerExit
   End If

End Function

Public Function ListCustomProps()
'Created by Helen Feddema 3-Oct-2006
'Modified by Helen Feddema 3-Oct-2006
'Lists DB properties created in code (as well as built-in properties)

On Error Resume Next
   
   Set dbs = CurrentDb
   Debug.Print "Database properties:"
   
   For Each prp In dbs.Properties
      Debug.Print vbTab & prp.Name & ": " & prp.Value
   Next prp

End Function

==================================
Usage examples:

Private dbs As DAO.Database
Private prp As DAO.Property
Private prps As DAO.Properties
Private lngDataType As Long
Private strPropertyName As String
Private strPropertyValue as String
Private varPropertyValue As Variant

Date
====
   If IsDate(Me![txtStartDate].Value) = False Then
      strTitle = "Invalid date"
      strPrompt = "Please enter a valid start date"
      Me![txtStartDate].SetFocus
      MsgBox prompt:=strPrompt, _
         buttons:=vbExclamation + vbOKOnly, _
         Title:=strTitle
      GoTo ErrorHandlerExit
   Else
      dteStart = CDate(Me![txtStartDate].Value)
   End If
   
   strPropertyName = "PropName"
   lngDataType = dbDate
   Call SetProperty(strPropertyName, lngDataType, dteStart)

   GetStartDate = CDate(GetProperty("PropName", ""))

Text
====
   strPropertyName = "PropName"
   strPropertyValue = CStr(cbo.Value)
   lngDataType = dbText
   Call SetProperty(strPropertyName, lngDataType, _
      strPropertyValue )

   strDocsPath = GetProperty("PropName", "")

Long
====
   strPropertyName = "PropName"
   lngDataType = dbLong
   Call SetProperty(strPropertyName, lngDataType, lngID)

   lngID = CLng(GetProperty("PropName", ""))

Integer
=======
   strPropertyName = "PropName"
   lngDataType = dbInteger
   Call SetProperty(strPropertyName, lngDataType, intMonth)

   intID = CInt(GetProperty("PropName", ""))

Boolean
=======
   strPropertyName = "PropName"
   lngDataType = dbBoolean
   Call SetProperty(strPropertyName, lngDataType, "True")

   blnValue = CBln(GetProperty("PropName", ""))


Saving to a custom property from a control's AfterUpdate event
==============================================================
Private Sub txtDate_AfterUpdate()
'Created by Helen Feddema 2-Sep-2009
'Last modified 2-Sep-2009

On Error GoTo ErrorHandler
   
   If IsDate(Me![txtDate].Value) = True Then
      dteSingle = CDate(Me![txtDate].Value)
      strPropertyName = "SingleDate"
      Call SetProperty(strName:=strPropertyName, _
         lngType:=dbDate, varValue:=dteSingle)
   End If
   
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: " & _
      Err.Description
   Resume ErrorHandlerExit

End Sub

Open in new window

0
 

Author Comment

by:Bob_Collison
ID: 41725937
Hi Helen,

Unfortunately I can't figure out what this is doing.

Could You please provide some sort of overview?

Thanks,
Bob C.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 41725965
<The issue is there is not a Table to store the Counter Field Values in>

if you read my post, you need to use TempVars collections
     "set the value of a tempvar variable in Event to add / update data in the table"
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 41726085
See my Filter by Form sample database, which uses this technique:

http://www.helenfeddema.com/Files/accarch248.zip

Here is a screen shot of the form:

Filter by form
0
 

Author Comment

by:Bob_Collison
ID: 41726502
Hi Experts,

Thanks for your suggestions.

Helen,
Having reviewed in detail your referenced Zip File I am unable to understand what is occurring and how it occurs.

Rey,
I don't know what 'TempVars ' Collections' are and there is no table associated with the data I am trying to report.

Thanks,
Bob C.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
ID: 41726511
you said <I have a Form that runs an Event to add / update data into a table. >

use the same Event to set the value of the variable, i.e.,
place the statement after the count/calculation is done

tempVars!Count1= me.txtCount1.value
tempVars!Count2= me.txtCount2.value
tempVars!Count3= me.txtCount3.value

in your report, you use the variables as the control source of your textbox
= nz(tempvars!count1,0)
0
 
LVL 31

Assisted Solution

by:Helen_Feddema
Helen_Feddema earned 250 total points
ID: 41726515
Can you post your database (or a cut-down version of it)?   That would be helpful.  As for my sample database, it uses custom database properties to store values that can be used elsewhere in the database, for example in reports.  If your form control has a calculated expression, then the value could be written to a custom property from the Click event of a command button, or directly from whatever code does the calculation, but I would have to examine the form to see which method would work for you.
0
 

Author Comment

by:Bob_Collison
ID: 41726545
Hi Experts,

Rey,
I now totally understand your solution and have implemented it therefore I am accepting it as the best because it is very simple. Believe it or not I wasn't aware of Temporary Variables

Helen,
Thanks for your suggestion but I am accepting Rey's as noted above.

Thanks,
Bob C.
0
 

Author Comment

by:Bob_Collison
ID: 41726547
Hi Experts,
I often have trouble closing questions and assigning point.
I wanted to assign them as follows.
- Rey 350.
- Helen 150.

Please arrange for the question to be re-opened or to just have the points assigned as I have indicated above.

Thanks,
Bob C.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now