Bob Collison
asked on
Access 2010 Report Data From Fields On Form
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.
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.
ASKER
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.
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.
in your report, you can create a control (textbox) and set the ControlSource of that control to:
=Forms!yourFormName!txt_Co unterField
=Forms!yourFormName!txt_Co
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
ASKER
Hi Helen,
Unfortunately I can't figure out what this is doing.
Could You please provide some sort of overview?
Thanks,
Bob C.
Unfortunately I can't figure out what this is doing.
Could You please provide some sort of overview?
Thanks,
Bob C.
<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"
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"
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:
http://www.helenfeddema.com/Files/accarch248.zip
Here is a screen shot of the form:
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
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.
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.
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.