473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Retrieving a field from the current record from a subreport plus complication

So the real problem is that I have a field named Print (reserved word). I can't change the field name because of reasons outside my control.

The goal of this code is to be able to click on a field and have that field populate a txtbox which can then be used as search criteria.

The code below gives an error because the subreport is not open. (Coincidentally this is the reason for the clunky code being used to populate the txtbox, so if you know a better way to do that please speak up.)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_Click()
  2.  
  3.     Dim strWorkOrder As String
  4.     strWorkOrder = Reports!rptsubIPACHistory!("Print")
  5.  
  6.     Forms!frmIPACHistory!txtSearchWorkOrder.SetFocus
  7.     Forms!frmIPACHistory!txtSearchWorkOrder.Text = strWorkOrder
  8.  
  9.  
  10. End Sub
  11.  
Dec 19 '16 #1
5 973
MikeTheBike
639 Expert 512MB
Hi
You do not say what the error is, but I don't think you can access a report's (or form's) properties if it is closed.
But I will stand corrected if this is the case!!??

Also, if it is open, I don't think you can refer to a SubReport or SubForm without going through (referring to) its main From/Report.

You would need something like
Reports!rptMain!rptsubIPACHistory.Report.Print
Or
Reports.rptMain.rptsubIPACHistory.Report.Print

Not very helpful, but if true, then you will need to come up with a different scenario to achieve what you want.

With more information on Form/Report/controls/field relationships and the process required someone may be able to help further.

MTB
Dec 20 '16 #2
Okay that will not work because Print is reserved. How do I get around this?

But the error it gives is that "the report isn't open or does not exist" but it does exist, and it's open on the form.

Any other sugestions?
Dec 21 '16 #3
jforbes
1,107 Expert 1GB
Mike is right, the Report needs to be opened first. That is also what your error is telling you.

Here is how you go about opening a Report: DoCmd.OpenReport Method (Access)

Once it's Open, you can use some syntax like this to get the value of a Control. Note this is the Report's Control Name, not the Field Name:
Expand|Select|Wrap|Line Numbers
  1. strWorkOrder = Reports("rptsubIPACHistory").Controls("Print")
Dec 21 '16 #4
So I have to open the report in the background and then make sure both are closed when exiting the form. Seems like a lot of work.

So here's another question.. why does this code work with the report not being open?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Req_Num_Click()
  2.  
  3.     Dim strReqNum As String
  4.     strReqNum = Req_Num
  5.     Forms!frmIPACHistory!txtSearchReqNum.SetFocus
  6.     Forms!frmIPACHistory!txtSearchReqNum.Text = strReqNum
  7.  
  8. End Sub
  9.  
Thanks for all the help so far guys! I'm new to VBA so I really appreciate it.
Dec 21 '16 #5
So I made it work, though I'm still not certain I understand why the code in Post #1 needs the subreport launched and the code in Post #5 does not, but I think it's because Post #5 links to the txtBox and not to the actual control source (on the subreport). Like I said, I'm not sure.

To solve my problem I simply changed the name of the text box from Print to PrintNum so that I could use the exact same format as in Post #5 and not worry about the reserved word at all. That said I still appreciate that bit of code for getting the value of a control, I'm sure that will come up in the future!

Thanks again!
Dec 21 '16 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tony | last post by:
I have a form in access that has 5 fields for a certain record: 1)Date mailed, 2)Date received, 3)Date completed 4)Foreign Content amount and 5)record number. If the foreign content (FC)is >15% of...
2
by: Paul Mendez | last post by:
I have a form that consists of 150 records and is still growing. there are times when I want to print a certain record of the form, say record 12. I go to file --> print and choose the page number...
3
by: Maria | last post by:
Is there another way to delete the current record in a subform from the main form, another subform or a sub-subform other than setting focus on a field in the subform and using run command...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
1
by: David | last post by:
Hi, I have a continuous form. For each record I have a field 'HeldDate' (Text Field from a table) Against each record I have a button which sets the visibility of this text box to 'True' and...
2
by: MLH | last post by:
Fields in MyTable: PostID PostDate RollQtyXfer RollDenomination RollCount37 RollCount23
4
by: magmike | last post by:
I've created a report for the purpose of printing a one page summary of a record. Of course, when I created the report, it gives me a page on every record. Can I create a button to open that report...
4
by: achroiet002 | last post by:
Hi, Please, can someone help me? My problem: I have put a command button onto a form, which retrieves two field values from the current record. With these two values, I am able to open a...
3
by: Ross Ferguson | last post by:
I need to build a query on one table using a field in a current record and the same field in the previous record. Essentially, I need to know the difference between the value in the current record...
1
by: John smith 38 | last post by:
Hi, hopefully someone can help me with this. I have a table and linked a form to it. My form looks nice (like a report) and has 1000's of records. Currently i can save each record as a PDF but...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.