I have a report whose record source is a query, say qryRecords. In the report header I want to add a lengthy notes field (longer than 255 characters). I have set up a table to hold these notes (with a field type "memo"), and because that table is separate from the record source for the report, I was going to put the Notes field in the report using VBA code.
In the open event of the report, I have added this code:
Dim rst as Recordset
Dim sql_qry as String
sql_qry = "SELECT notes FROM tblNotes WHERE id = 1;"
Set rst = CurrentDb.OpenRecordset(sql_qry)
rst.MoveFirst
Me.txtNote = rst![notes] 'I get the run-time error on this line
Unfortunately I get a run-time error where noted ("You can't assign a value to this object"). I found a person with a similar issue on a form, and the suggestion was to move the code from the open event to the OnCurrent event, but that event doesn't exist for a report. Any suggestions? Thanks.
--- Original Question ---
I have a form with an unbound text box (txtNotes), and when the user opens the form, the text box is populated with text that is longer than 255 characters (it concatenates various fields from the database). This works with no problem.
There's a button on the form that opens a report, and in the report, I set the Control Source for a text box to Forms![frmMain]![frmSub]![txtNotes], which is the text box mentioned above. That works too, but for some reason the text on the report is truncated at 255 characters. The form's text box is unbound, so there's no underlying table to limit the length. Does anybody know why this would happen or if there's a workaround?
Most likely when the data from the field is being cast as a Text type rather than as a Memo. Really there's no way to explicitly cast a Text as a Memo (you can go the other way around though with CStr). I had problems with truncation on the form as well when experimenting with this scenario.
I'd suggest you are probably generating this field on the form in the wrong way. Dollars to doughnuts you could generate it in a query (used in the form's Control Source), rather than concatenating it together and placing into an unbound field. Likewise, you could then use that same query as the control source for the report that you are opening.
If all of that is truly impossible, I'd point you at dumping the values from the form into a table specifically for the report and then using the table as a control source for the report.
---- Edit ----
I still contend that you can add it to your Report's data source. In my example below, I've tacked on tblNotes to a select on the Bar table.
SELECT bar.f0, bar.f1, bar.f2, bar.f3, tblNotes.notes
FROM bar, tblNotes
WHERE tblNotes.id = 1;
Yes, if there is 300 rows of Bar, you'll get 300 copies of the same Notes field, but that's a minor problem.
Form there, you just make txtNote's data source the tblNotes.Notes column. txtNote can certainly exist in the report/page header, and when MS Access generates it, it will only use one row. I'm not sure if picks the first/last row, or random row - never the less since they are all the same, it doesn't matter.
Related
Here's the crux of the question, I have 26 compliance queries to run, in a previous question it was suggested that I should filter a single query, or two, on a single report. I like this idea, and have rewritten the query to pull all available data from all the fields, this query works fine. The report will work fine as well, as it does with a model query that I had coded up beforehand. What I would like to do is this:
The end user is being given an interface in access that is locked down, I want them to click a button, and that button will run the query and send to the text box just the field that is called for.
I have tried doing this through VB using the where clause and aliasing the column being called, this did not work at all. I have the report currently pulling the correct data, but not displaying the dates along side it. But it is filtering correctly aside from that.
So what needs to happen is this : Button click : Query runs, and is filtered for "Compliance Issue 1" and puts the dates in "Compliance Issue 1" in the text box on the report.
Right now... I get a list of names, the correct list of names, but an empty column.
I have tried using OpenArgs, but all it did was fill in the date column with "Compliance Issue 1" not the actual data in that column.
Is what I am trying to do even possible in access, and if so does someone have a reference or suggested starting point.
My background : 6 Months of python coding, 3 months of SQL , and some limited access from 20 years ago.
As noted, using the filter of the openreport is without question the way to go (one would not write a whole bunch of different queries - you can send/have any filter for that report - you can EVEN use a sub query in the filter that you send to the report.
As for displaying values in the report that are not from "rows" of data?
There are two approaches that work quite well.
First up, is you have that launcher form. This of course allows the user to select critrea - maybe even some nice combob boxes. These selections take care and you build up the filter in code that you pass to the report.
As for text boxes to be filled out from that form and inclluded in the report?
If they are static values from the report (say filter options, or even just a notes box that you could type in some text? To display such values in textboxes on the report?
You can directly set the text box data source (in the designer) to the report propter form like this:
=(forms!MyPromptForm!notes)
So, any value you shove into text boxes on the report prompt form can thus be displayed in any text box on the report with the above type of expression. And it does not even take code to achieve this goal. So, you could say with above enter some notes into that text box, and thus on the report, whatever you typed into that text box will now show up in the report. You just drop in a text box onto the report, and set the data source of the text box to the above expression that references the form with the values we want from that form.
The next approach, and I often use this in the case that some value/expression/calculation has to occur for each row. In this case, you can use the reports on-detail format event. This allows you to run code for EACH row of data.
You are free to run ANY code in that event - and that includes after running such code to set a text box in the reports detail section.
So, say the query only had the Hotel ID (PK). This is a lame example, but you could then write this code in the on-format event of the reports detail section.
dim strSQL as string
dim rst as DAO.RecordSet
strSQL = "SELECT HotelName from tblHotels where ID = " & me.HotelID
set rst = CurrentDb.OpenRecordSet(strSQL)
me.HotelName = rst!HotelName
rst.Close
So in above, we assume that a row text box is called HotelID, and then in code we build a whole sql query from scratch, pulled the row data from a table, and then SHOVE/SET the value of the un-bound text box called hotelName.
As noted, the above is a simple example, but we are free to run any code we want, pull any data we want, and set the value of ANY text box for the given detail section ONE row of values.
So, above shows two approaches. The first approach is code free - and you can put forms! expression directly into the report, and the values from that report prompt form will thus show up directly in the report. However, if you need VBA code to run for each row, pull values, walk the dog, and THEN set a text box on that one details row of data, then you are as above shows free to write procedural code in the report that fires + runs for each row of data - and that means you can quite much do anything you want in terms of running code. I mean, even that on detail format event COULD pull values from your report prompt form, but as the 1st example shows, you can shove in forms! expression directly into a text box - and those forms! expressions can be values from a existing form that is open before the report is launched.
I have a report that changes based on the query used in the record source.
I did this to consolidate 6 different reports that printed the same formate and to the same label printer but they all used different data types/sources. I was able to convert all by 1.
The one I am having trouble with is one where there is a form, with a combobox and a textbox. The combobox has a table that its connected to with 11 different symbols ranging from Hearts to & and # stuff like that. The textbox will take any number/text combo.
When I run a query that I set up with [Forms]![frmPrintPtouchLabel]![txtName] and [Forms]![frmPrintPtouchLabel]![cmbSymbol].
The query pulls the right information except for the symbol that columb is left blank. Can anyone provide any reasoning as to why this is happening and how I can fix it?
Thank you.
Looks like there was fluke somewhere in my code or I was just over thinking something. After setting up a blank query I set a field: Symbol: [Forms]![frmPrintPtouchLabel]![cmbSymbol], and a field Name: [Forms]![frmPrintPtouchLabel]![txtName]
and I set up a button in a form that does DoCmd.OpenQuery "qry_TestQuery", in that same form there is the combobox with the Symbols, and a textbox for the Name, when I input those two and click the button the query opens with the proper information. Thanks for all that helped.
Working with a MS ACCESS 2010 accdb file. Within a table, on one particular record, I am experiencing something odd with a text field.
The text field is shown to be populated with Gzzzzzz. However, clicking on the fields [down arrow], [Text Filters], [Equals...] and pasting Gzzzzzz returns nothing. Then, clicking on the fields [down arrow], the shown field populations include GzzzzzzGzzzzzz: not, Gzzzzzz. Selecting GzzzzzzGzzzzzz a record is returned with the field populated with Gzzzzzz.
Showing all the fields again, and editing the field to Azzzzzz. Then, filtering on Azzzzzz again returns nothing. Then, filtering field options show AzzzzzzGzzzzzz: which when selected, returns Azzzzzz.
Also curious, when I filtered as above then look at the Property sheet, at this point the Filter shown is ([TableName].[FieldName] = "Azzzzzz ...missing the final "). However, when I filter on a working record, the Filter is shown as ([TableName].[FieldName] = "Whatever"): meaning shown completely with the trailing ").
The field is not indexed. There are no defaults or formatting. The table is related to three other tables: but, not on this field and not with Enforce Referential Integrity. Other records in the table are fine and work. Just this record's field.
Does anyone know how this happens? Is there a method to repair the record?
The field in the record probably contains
Gzzzzzz
Gzzzzzz
(with a newline in there) which isn't easily visible in a single-line textbox.
Use Shift+F2 to open the Zoom window. Or "tab" into the control, so everything is selected. Then delete the whole content and re-enter.
I have searched everywhere for this and tried different criteria but for whatever reason the form which has a control box set to open a report which is based upon a query will not pull the data within the date range. Instead keep getting enter parameter value dialogue box.
The criteria in the query is stated as Between [Forms]![Form1].[StartDt] And [Forms]![Form1].[EndDt]
The form has two date inputs StartDt and EndDt and is pointed to open the report. Without the above criteria in the query the form opens the report and produces all the dates. So at least it allows me to enter dates and is connected to the query and report but without the criteria fails to isolate data within the required range.
When I place into the query containing the criteria (as above) under the appointment date field all im getting are two parameter value dialogue boxes one after the other displaying Forms!Form1.StartDt and the second, Forms!Form1.EndDt.
Apologies for being long winded but am desperate to solve this issue am new to access.
Thanks to everyone for any input.
Iain
It seems you have an error in your names. One of the easiest ways to check form names is to use the immediate window. Type ctrl+G and you will end up in the code window with the cursor in the Immediate window. With the form open and a date filled in, type or paste
?forms!form1!StartDt
Into the immediate window and hit return. If you get an error, it means that you have a name wrong somewhere along the line, either your form is not called Form1, and form names can be a little complicated, or your control is not called StartDt. So this is where the version of Access comes in. In Access 2010, if you type Forms! on the criteria line of a query and wait a second, it will give you a list of forms. Pick your form from the list and type ! after the name, Access will come back with a list of controls. Pick your control. You should now have the right form and control name.
I have been battling with this problem for weeks now and simply cannot find a solution.
I am using MS Access 2007
I have a table caled "Policy Information" where all of my data is stored. I have created a combox box to autofill a few text fields using a query called "BC Allocation Query". By choosing from the combox269 field I created then 6 other text fields are automatically completed. I used the function =[Combo269].column in the control field of the text field I want auto-completed.
This all works great however I cannot seem to relfect the information from the text boxes which are auto-completed to relfect in my Access Reports whcih I have set up.
Please can someone assist me withthis before I jump off a cliff:)
Are these text fields on the form bound to fields in the source for the form? If not, they are unbound, and you need to write code to save this information into the table when you navigate away from the record or close the form. If they are bound, you need to programmatically force a save of the record when VBA changes values, otherwise - you might get the dreaded 'values changed by another user' verbage in an error.