Solved

MS Access - Assign a table field value to a variable in subreport vba

Posted on 2013-05-22
2
2,415 Views
Last Modified: 2013-05-22
Hello,

In my Microsoft Access database, I have a report object named 'ReportA' and this report contains a subreport named 'ReportB'.

The Control Source of the subreport 'ReportB' is 'TableB'.

The 'TableB' has a field named 'TelephoneNumber'.

In the On Format event (VBA) of the detail area of the subreport 'ReportB', I want to assign the 'TelephoneNumber' field value of the current record to the variable named 'VariableA'.

I have tried:

Dim VariableA

VariableA = [TelephoneNumber]   'Didn't work, I don't know why because this code works on non-SUBreport 

VariableA = Me.[TelephoneNumber] 'Also didn't work

VariableA = Me.TelephoneNumber 'Also didn't work

Open in new window


Can someone please give me the correct code?

Thank you,
0
Comment
Question by:ZKM128
2 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
Comment Utility
You can try referring to it like this:

Me!TelephoneNumber

If that doesn't work, the you can actually add the Field to the report somewhere, and then refer to it. I've found this to be the most foolproof method when I need to refer to a Field in a Report.
0
 

Author Comment

by:ZKM128
Comment Utility
Thank you LSMConsulting,

Me!TelephoneNumber didn't work but I have created a hidden text box on the subreport and

VariableA = Me.TextBoxName

Open in new window


worked out OK.

I wanted to know the method of accomplishing this without creating the hidden text box but if this is the only way I'll create a hidden text box for all the field values I need.

Thank you.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

772 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

10 Experts available now in Live!

Get 1:1 Help Now