In MS Access - How do I use a macro to change the caption of a label so that it matches the caption of a text box in a report? - ms-access

The label that I'd like to change the caption of has the name: "lblEventNameLabel"
The text box that holds the value that I want to update the label has the name "txtEventNameLabel"
The name of the report is "rptBookingConfirmation"
I've got as far as creating this Macro in the "On Load" part of the report:
SetProperty
Control Name lblEventNameLabel
Property Caption
Value [txtEventNameLabel]
When I open the report it updates the caption to "[txtEventNameLabel" instead of the value that is in the text box. I've also tried chaning the Value in SetProperty to [rptBookingConfirmation]![txtEventNameLabel] and [Reports]![rptBookingConfirmation]![txtEventNameLabel] but those have the same result.
Any help would be much appreciated!

Me.lblEventNameLabel.Caption = "Your Text"

Related

Multiline property problems

I have a column in my database that is set to memo. I am trying to view the data in a textbox.
I have enabled new line in field from the Enter Key Behaviour property but all the data from the record is now showing - What am I missing?
The data is being pulled from a list box, example code below:
Textbox1 = listbox.column(1)
Thanks in advance
This has nothing to do with the EnterKeyBehavior property of the text box.
http://allenbrowne.com/ser-63.html
Row Source
A Memo field in the Row Source of a combo box or list box will
truncate.
Don't use memo fields in combos or list boxes.
You'll need a different method to load the text box, e.g. read the ID from the listbox and use DLookup().

Access 2007 reports, hiding fields?

I have a report in Access 2007 thats populated with data from SQL SERVER (running on a vb6 application). This report has two subreports that display data. The first Subreport has a Label, "CHILDREN" and the subreport next to it displays Names of children. The 2nd subreport has a Label "PETS" and the subreport next to it displays PetName, and TypeOfPet. In most cases there are pets in every family, however, for some clients, there are no pets. What I'm trying to do is make the label PETS invisible if there are no pets, so the Label is not on the report by itself. How would I go about doing that?? Is this something I have to code?
The following link shows how to hide the label if no data: https://forums.techguy.org/threads/solved-access-2003-hide-field-labels-on-reports-when-value-is-null.660825/
Below are the steps required:
1. Delete the label from the text box.
2. Add new text box in place of the old label.
3. Format the new text box same as other label.
4. Set it's "Can Shrink" property to "Yes".
5.Bind the 'new' label to an expression that will solve to "" if the [Pet] field is blank or to the text string "Pets:" if the [Pet] field is not blank.
6. Change text box Control Source field on the Data tab of the Properties window. In it put:
iif(isnull([Pet]),"","Pets:")
This will put a zero-length string into the text box when the [Pet] field is null and the text "Pet:" when it is not null
7. If the field is blank, it could be null or a zero-length string (""), or could have any number of blank spaces in it. Rather than use "IsNull", use a combination of functions that will solve. i.e.:
Iif(trim(nz([Pet],""))="","","Pets:")

copy value entered in unbound textbox to label after pressing button

I have an unbound text box on my form which the admin can enter a date of when records were last updated. I want this date to be copied to a label after pushing a button so that it holds the date instead of it do disappear after closing the form.
does anyone know if this is possible and how it is possible?
For creating a variable that can be used AFTER the form is closed:
Create a new module (in code window, click 'Insert | Module'
Insert the variable name(s) and types you want available everywhere. i.e.
Global dtLastUpdated As Date
Global strSaveSomeName As String
Save the module as mdl_Globals
Add code wherever needed to set the variable, then can reference anywhere.
If for use during the form, use the following: where 'lblForUnbound' is the Label field and 'txtUnbound' is your unbound text box
Me.lblForUnbound.Caption = Me.txtUnbound.Text

How do I substitute one entry for another an MS Access report?

I recently started working with MS Access 2010, and I am trying to generate labels from a form that I have created. In the form, three pieces of information are put in by the user: style, color code, and unit of measure (UoM). The style numbers appear the same way on the form and in the report, and I have been able to get that to work.
However, for the color code, I need both the inputted color code and the actual color to show up on the report. I have a table that has all of the color codes with the corresponding color names. I cannot figure out how to get the text box that is supposed to show the color name to show it. I know virtually no SQL, but I found information on it on the internet and pieced together this code in the ControlSource for the text box the color name is supposed to be in:
=(SELECT [Description]
FROM [Color]
WHERE([Forms]![Box Label Form]![ThirdJoined]=[Color]![ColorCode]))
[Description] is the name of the column within the [Color] table that gives the actual color name.
[Box Label Form] is the name of the form.
[ThirdJoined] is the name of the input text box within the form.
[ColorCode] is the name of the column within the [Color] table that gives that color code.
This code doesn't work, and only results in #NAME appearing in Print Preview view. How can I get this to work, either code-wise or otherwise?
You cannot set the ControlSource of a textbox to a SQL statement. You could set it to a DLOOKUP function to lookup a single value. You also need to separate out the reference to the form control using concatenation (&).
=DLOOKUP("Description","[Color]","ColorCode='"&[Forms]![Box Label Form]![ThirdJoined]&"'")
I'm assuming the Color is a text-value so the form-value needs to be enclosed in apostrophes.
If this expression is used on the form [Box Label Form] then you don't need to qualify the name of the Control:
=DLOOKUP("Description","[Color]","ColorCode='"&[ThirdJoined]&"'")

Use table field description on form

I would like to display a field's description on a form. How would I accomplish this? For example, table name is tblbureau, field name is Counsel with a description 'General Counsel for the Defense', form name is frmCounsel. I'd like to use a control (textbox?) that displays the full description instead of using the default label for the field name. Thanks.
If you have used the form wizards to create the form, any descriptive text is added to the StatusBarText propery. This is even true when you create a blank form and drag fields from the field list to the form. You can refer to this property for your message box, or just refer the user to the statusbar. You can also update the ControlTipText property with the StatusBarText property.
MsgBox Me.ATextBox.StatusBarText
Using the above will save coding to get the description:
Currentdb.TableDefs("atablename").Fields("afieldname").Properties("Description")
Note that the description property is not available for fields when you have not added a descrition, so the above would cause an error.