How to reference a control's properties in Access - ms-access

For instance, I have a query which takes as a parameter the text property of a drop-down box [DDB1] of Form1.
How do I reference the property?
My stumbling around google has suggested that it should be something along the lines of
Forms![Form1]![DDB1].text
But I have been unable to find a definitive syntax for such references.
Any ideas?
Semi- OT - the Access2003 help, which contains links to a lot of Microsoft web pages, returns a lot of 404s when trying to load them. Is this just coincidence? Or end-of-lifing by stealth?'

To have a query reference a combo box on a form, use this syntax:
Forms!MyForm!MyComboBox
This will retrieve the selected value property of the combo box (the value of the first column, if it is a multi-column combo box).
If you want the selected value of a different column in the combo box, it is:
Forms!MyForm!MyComboBox.column(n)
Unlike most numeric indexes in VBA, n is zero based (the second column is 1).
To reference the text property, the combo box must have the focus.
The help file is apparently suffering from link rot. Here are some links in MSDN to use:
Access 2003 Programming Reference
http://msdn.microsoft.com/en-us/library/aa167788(office.11).aspx
Access 2003 Language Reference
http://msdn.microsoft.com/en-us/library/aa663079(office.11).aspx

You have in fact multiple ways to refer to a control with MS-Access. In addition to #Robert Harvey proposal, you can also write:
forms(myFormName).controls(myControlName)
Despite what #Robert says, you can access most properties of a control without setting the focus on it. One important exception is the ".text" property, which refer to the text appearing in the control, and where the focus must be set to the corresponding control.
Most of the time, the .text property is equal to the .value property, that can be accessed without setting focus on the control.
Thus, this property is useful only for controls of the combobox or listbox type, where the bound column (that gives the .value property) differs from the displayed column (giving the .text property).

Related

Object variable or with block variable not set - Access 2013

Please press here to see my gif that could provide a better understanding of my problem.
As you can see above that it's kinda a problem, but I don't know what to do, so I am hoping that some of you could tell me what and how to do with this. It's my first time to see this " Object variable or With block variable not set" problem...
I don't have any code to show you because I was using the default way to make bound textbox and then using a subform with lots of subform. (See the gif for the idea of the layout)
It's in danish language, but I think this should be a common problem as everywhere in the world, so...
It's in access 2013, in case you was asking.
uhm... If there're any questions, please ask right away.
So you have a subform within a subform and you are receiving an error when trying to set the properties of the innermost subform that link it to it's parent form (which I will refer to as the middle subform).
Here's a thought. Try opening the "middle subform" in the designer (ie do not open the main form, just the middle subform from the navigation panel). then set the properties. This has a better chance of working.
Here's some references I used for inspiration, the first of which stresses the fact that the linked "fields" are actually EITHER control names OR field names from the dataset and why it is often best to use control names.
http://www.fmsinc.com/microsoftaccess/forms/subform/master-link-fields.asp
http://access.mvps.org/access/forms/frm0031.htm

How to make a textbox display a different field than it controls?

So at the top of my page I have a combo box to select the current employee. The form is chiefly made up of checklist items to be completed. I set up a macro, so that when a checkbox next to the item is clicked, it will populate the 'CompletedBy' field with whatever value was in the combo box at the top of the page. That way they can select their name once, and then check off any items they have completed, and their respective name will be recorded for each item they have done.
HOWEVER I want it to DISPLAY the employees name, but actually manipulate the 'EmployeeID' field.
So how do I make a textbox display a value, but manipulate a different value in a table>? Or if this is impossible, what other paradigm could I use to accomplish this?
This is a tutorial on how to bind combo box to primary key but display a description field: this works on old version of Microsoft Access. I don't know if newer versions of Microsoft Access use a different and simpler approach (i.e.: .DisplayMember and .ValueMember properties of a ComboBox in VB.NET).

VBA: Why must I set focus to control every time?

I am creating a personal Library Inventory system using an Access 2007 database. In code, whenever I reference the .Text property of a form control, whether it be changing the value, or simply checking the value in an IF statement, I get prompted with Run-time error '2185': You can't reference a property or method for a control unless the control has the focus.
Why is this?
For setting the .Text it's not a huge deal, but when I'm checking the value in an IF statement, I can't set the focus when I'm checking multiple conditions.
Use .Value instead - that doesn't require setting focus first. From the documentation, for example for the TextBox control (emphasis mine):
While the control has the focus, the Text property contains the text
data currently in the control; the Value property contains the last
saved data for the control. When you move the focus to another
control, the control's data is updated, and the Value property is set
to this new value. The Text property setting is then unavailable until
the control gets the focus again.

Can I create a drop-down list (as opposed to a combo box)?

Creating combo boxes in Access is easily enough. However, drop-down lists are slightly easier for users when there's no need to edit or add values to the list.
Is there a property I can set to make a combo box control manifest as a drop-down list? Is there a custom ActiveX control available with drop-down style?
See whether the combo box .Dropdown method gets you close to what you need. I cribbed this example from the Access help topic:
Private Sub SupplierID_GotFocus()
Me!SupplierID.Dropdown
End Sub
If I am understanding your phrase "manifest as a drop-down" correctly, I think you mean that you want to restrict the user to selecting from a set of pre-populated options only.
Provide a List of Approved Values to Select
For example, if you want them to select a Month, and there are only twelve valid entries Jan-Dec, you can provide a list of months from a query, table, or direct input into the Combo Box's Row Source property.
Keep the User from Adding New Values or Editing Existing Values
What I think you may mean by "manifesting as a List Box" is that you can also then restrict the user to only selecting from your provided values by setting the Limit to List property of the Combo Box to Yes. Setting this property will restrict your users to your list, and not allow edits or new list entries. Remember to take addition steps if you need to make sure the user has selected one of your list values.
Use Dropdown and an Event like On Got Focus together
The Dropdown method "opens" the list so that the user can see the available options. For example, you can set it to the control's On Got Focus Event property so that the user will see some or all available options when the focus is set to this control.
Best of luck!

Textbox in Reporting Services - show text or hyperlink

I have a report in SQL Server Reporting Services which should show
a text box with a static text for "normal" users
a text box with a hyperlink to open up a new details windows for "super" users
The user level is determined by a parameter being passed into the report.
How can I achieve this? I tried to create a textbox with a text span inside that has a hyperlink, and then just leave it blank for "normal" users, but that doesn't seem to work reliably.
Is there a trick or method to get this to work? I'm thinking I need to add some code to the report to check the user level and then either insert a static text, or a text with a label, into that target textbox. But how do I do that (not having any VB/VBA/VB.NET experience....)
Thanks!
Marc
To make the hyperlink, you should be able to use an expression like
=iif(Parameters!IsSuperUser.Value = True, "http://some link","#")
in the Action property of the textbox, if you set the Action to "Jump to URL".
To control the content of the textbox, use a similar expression in the Value property.
(This is true on SSRS 2005 - I don't have access to 2008)
Edit
Unfortunately, hyperlinks in SSRS aren't formatted in a way to make it clear that they're hyperlinks. The only way to achieve this would be to add similar conditional formatting expression to the Color and TextDecoration attributes to make the field appear in a different colour and underlined when it is a hyperlink.
I haven't got SSRS installed on the machine that i'm writing this on so i can't give you an exact guaranteed bug free answer, but this answer should set you on the right track.
Have two textboxes, both located in the same absolute position (inside a container element if necessary). Fill them both with their correct values. Then just control their visibility by toggling their Hidden property with an expression:
=(Parameters!UserLevel.Value = 'Admin')
Obviously UserLevel is the name of the parameter being passed in to the report. The 'Admin' value is for illustrative purposes, personally i would use an int value to represent the user level, much like using an enum.
Remember that it is the Hidden property you are setting, so you have to reverse the logic you would have used if you were setting a Visible property :)