Setting properties for combobox in the form.open event Access 2019 - ms-access

I have the following piece of code located in the open event of a form.
If GetUserName = "Bob" Or GetUserName = "Ned" Then
Me.cbo_Position2.LimitToList = False
Me.cbo_Position2.AllowValueListEdits = True
Me.cbo_Position2.ListItemsEditForm = frm_MasterDropDown_lookup
End If
I'm using this code to set who can edit a combo box list. The combo box is bound to a field on the form and the combobox info is in a separate lookup table. What I want to know is whether or not these properties can be set as the form opens.
When I run this code, it executes with no errors but the properties do not change. I also tried doing 'Me.Refresh' at the end but that did not help. My assumption at this time is that they can't be "set on the fly" so to speak. If not, I was wondering if there is something I'm missing to get this to work.
TIA,
Tim

From Access help:
1.If you set the combo box's BoundColumn property to any column other than the first visible column (or if you set BoundColumn to 0), the LimitToList property is automatically set to Yes.
2.When the LimitToList property of a bound (bound control: A control used on a form, report, or data access page to display or modify data from a table, query, or SQL statement. The control's ControlSource property stores the field name to which the control is bound.) combo box is set to No, you can enter a value in the combo box that isn't included in the list. Microsoft Access stores the new value in the form's underlying table (table: A database object that stores data in records (rows) and fields (columns). The data is usually about a particular category of things, such as employees or orders.) or query (query: A question about the data stored in your tables, or a request to perform an action on the data. A query can bring together data from multiple tables to serve as the source of data for a form or report.) (in the field specified in the combo box's ControlSource property), not the table or query set for the combo box by the RowSource property. To have newly entered values appear in the combo box, you must add the new value to the table or query set in the RowSource property by using a macro or Visual Basic event procedure (event procedure: A procedure that is automatically executed in response to an event initiated by the user or program code, or that is triggered by the system.) that runs when the NotInList event occurs.
Example for setting property:
Forms("Order Entry").Controls("States").LimitToList = False

Related

MS Access using ApplyFilter from Macro Builder with combobox shows input parameter box

This time I'm trying to work on an MS Access application. I have a split form populated using a SQL query. Now I want to filter this form using a combobox which is located in the header of the form. This CB is also populated with a SQL query:
SELECT DISTINCT [ConsultQ].[ClientName] FROM ConsultQ;
I have added an embedded query to this Combobox which should filter the form. The values shown in the Combobox are correct. But when I select a value from the box a popup show which asks me for input.
The ApplyFilter action is set to:
So, apparently, the ApplyFilter action cannot retrieve the selected value of the Combobox. What am I doing wrong here?
When I enter a name in the input box, the filter is applied correctly. So the filter works, but I cannot set the filter using the selected combobox value.
It must be something simple, but I cannot find it.
I'm using MS Access Office 365 version.
Remove the [Text] property. You want [Value] and [Value] is the default so doesn't have to be explicitly referenced.
Also need full path reference to combobox.
Forms!yourformName!cboClient
However, really should use ClientID to filter records. If the combobox has ClientID as first column and first column is set as the BoundColumn, then combobox value is ClientID, not ClientName.

Access 2016 issue - Can't get 2nd combo box to populate depending on value of 1st combo box

I have an Access database with a form. The form has 2 combo boxes (Combo0 and Combo2). I'm trying to get Combo2 to populate based on the value in Combo0. I'm trying to do this with an AfterUpdate event.
When I try to select a value in Combo2, I get the following message:
The record source" SELECT........" specified on this form or report does not exist.
The name of the recordsource may be misspelled, the recordsource was deleted or renamed, or the recordsource exists in a different database.
In the Form or Report's Design view, or Layout view, display the property sheet by clicking the Properties button, and then set the RecordSource property to an existing table or query"
This seems like a simple thing to do but I'm obviously missing something here. Any suggestions would be GREATLY appreciated .....Thank you
I have a Combobox1 set for my Client Company and then a Combobox2 set for the Client Contact. My Combobox2 changes depending on which Client Company I select.
Combobox2 Row Source Type = Table/Query
Combobox2 Row Source = see below
SQL
SELECT [Clients - Contacts].ID, [Clients - Contacts].[Full Name], [Clients - Contacts].Company
FROM [Clients - Contacts]
WHERE ((([Clients - Contacts].Company)=[Forms]![dshbProjectDetails]![CompanyID]));
Picture: Query Builder
After Update Event on Combobox1 = Macro: Requery; Control Name Combobox2

Using a calculated field value from a form text box in a query

I have a calculated text box on a form. How can I use that value in a query? The value is based on many other calculations done on the form as well.
I was hoping I wouldn't have to re-do all the calculations in the query.
Providing the form remains open when the query is evaluated, you can reference the value of any control on the form using the following syntax in your query:
Forms![Your Form Name]![Your Control Name]
In the case of referencing the value held by a control on a subform, consider that the subform is just another control on the parent form, and so the chain of references becomes:
Forms![Your Form Name]![SubForm Name].Form![SubForm Control Name]
You can test the value obtained by simply creating a new query in Access with the SQL code:
select Forms![Your Form Name]![Your Control Name] as FormValue
When run, this will yield a single record displaying whichever value was held by the control Your Control Name on the open form Your Form Name at the time of execution.

set Access database table field with form check box

I am trying to set the value of a number field on a table using the value of a bound checkbox on a form. The value needs to be 40 if checked and 0 if unchecked. I'm new to this and have no idea where to start.
No, the checkbox was added to a form and is bound to a number field in the table. The data is imported from an antiquated system that uses codes that most users would not understand, so if it says 40 in the table I just want the form to show checked, all other values should show unchecked, and I want the user checking/unchecking the checkbox to update the table accordingly.
The checkbox is to indicate whether or not a customer has provided direct debit information. 40 would mean they have, anything other than 40 would mean they haven't.
One way do this is using VBA in Access. The way you access VBA console in Access, is when in your form's design view, right-click the checkbox box control and choose "Build Event" from the menu. Make sure your control's Triple State is set to "Yes" in the property for the checkbox in the form's design view. Also, be certain that the checkbox's Control Source is pointed to the field in the table where you're putting the data.
Please note that prior to doing this, it is helpful to prefix your control's name... something like chkDebitInfo... "chk" stands for check box. You can change the name in the property sheet for the control, by clicking on the Other tab, and simply change the default name, which might say something like Check625. Also, you want to set the table field's data type to an "Integer" so it holds the value.
Once you're in the VBA console, after having chosen Build Event... you're presented with the control's sub procedure. I've done a sample for you:
Private Sub chkDebitInfo_Click()
If chkDebitInfo.Value = True Then
chkDebitInfo.Value = 40 // Sets the checkbox to 40 if checked
ElseIf chkDebitInfo.Value = False Then
chkDebitInfo.Value = 0 // Sets the checkbox to 0 if un-checked
End If
End Sub
I've commented the statements that set the checkbox values if checked or un-checked, so you don't have to add those. Just substitute the control name for your's, or use the default name if you haven't changed it, and you're good. Then when the check box is checked or not checked, you'll see the values populated in the database table.
Alternatively, you can set the checkbox to default value for when the form loads, but you haven't stated it, so I won't go into it. Hope this helps. Let me know if I need to expound further.

access 2010 expression builder

I want a text box to contain data which is a calculation based on 2 other control field values - only if it's value is null (ie the current value of the column in the database is null).
So I entered =([control1]*[Control2])/1000 in the expression builder for the default value property - however the result always shows the textbox to be empty (even tho control2 and control2 contain values).
How can I achieve this? Can such an operation only be done in code-behind ie VB??
thanks,
KS
I think you're talking about a control bound to a field in the form's record source. And when the underlying field is Null, you want the control loaded with your calculated value.
If that interpretation is correct, you can do it from the form's On Current event.
If IsNull(Me.txtYourTextBox) Then
Me.txtYourTextBox = (Nz(Me.control1) * Nz(Me.Control2)) / 1000
End If
That will load the computed value into the text box, allow the user to change its value if desired, and store the value to the bound field when the record is saved.
If the bound field is not Null, its value will be displayed in the text box without alteration by the On Current code.
Is that what you want?
To accomplish this using VBA, add a Form_Load Event. (Open the form in Design View and in Form properties click the Event tab and choose Event Procedure for "On Load" and click ...)
This example uses [TextField] to refer to the table data.
Private Sub Form_Load()
TextControl.SetFocus
If IsNull([TextField]) Then
TextControl.Text = ([Control1] * [Control2]) / 1000
End If
End Sub