Using Button to change a value - Access - ms-access

I have a form that takes in a class number, and then displays the class roster for the given class.
I am new to Access, so this may be a simple question, but how can I use a Button that is called Find Class that can be pressed so the user can change the class number?
Right now, I have ClassNbr as a field in my query, and then I am using that field in my report as an unbound textbox. It has a default value that is automatically displayed when the form is opened. Is there a way I can use a button to edit this ClassNbr field?

Related

Paste a value in a textbox on the second tab of a navigation form access vba

I'm quite new to VBA and I've been looking around but cannot seem to find a solution to my problem.
I have made a navigation form (frmNavigation) with 3 buttons, each referring to a different form, let's call them frm1, frm2 and frm3. In the navigationform the control buttons to switch between tabs are all named differently (btn1, btn2, btn3), but the subform that shows either frm1, frm2, or frm3 has the same name: “NavigationSubform” (this shows a different form depending on which tab is clicked on, based on the 'navagation target name' referring to frm1, frm2 and frm3).
When I want to refer to a textbox (txtBox1) on form 1 (first tab) and insert a value i can do this by:
Forms!frmNavigation!NavigationSubform.Form!txtBox1.Value = "insert awesome text"
But how would I refer to txtbox10 on the second tab (frm2)? Just using the following does not work:
Forms!frmNavigation!NavigationSubform.Form!txtBox10.Value
You then get the error 2465 (can't find the field).
I’ve been trying many different things, but can’t seem to get it right. So how do I refer to a textbox on a different tab than the first one?
Help us much appreciated!
Only one subform can be loaded at once. So you've just got to break this process into two steps.
Store the value from txtBox1 somewhere outside of the NavigationSubforms (a textbox on the parent form with visible = no, a global variable or a table works).
In frm2's On Load event, set txtbox10 to be the value you stored.
Just note, that you will need to add conditions in the On Load event if you want to avoid that textbox being set to an empty string or a wrong value if you have a setup where your filter is changing.

Clear out dropdown value once another drodown value is changed in vba access?

I have three combo box controls(MFG, Code, and GrpID) in my VBA access form. Once the user selects an option from the first combo box (MFG), rest of combo boxes give me available options. But I need to do some validation i.e. what if the user decided to change the value of first combo box? The values of rest combo box should be cleared. All I need to do is once the first combo box is changed the second and third combo box need to be cleared out or at least set to focus on them so that users will realize that they can't use old values as first value is cleared in the first combo box. I added a code block 'AfterUpdate for first combo box as shown below:
Private Sub MFG_AfterUpdate()
Code.Value = " "
GrpID.Value = 0
End Sub
The problem after writing above code is: they don't get empty until they(Code and GrpID) get clicked. In other words, I need to click them to empty them every time I change the value of MFG. Can anyone direct me how do I clear them or at least focus them?
Set the combo to null to wipe any displayed value in them;
Me.Code = Null
Me.GrpID = Null
This assumes your combo controls are called the same as your field names.
Edit for clarity: Including the Me. makes sure your are changing the form control values. If your field names are the same as the controls then Access will change the underlying field values, and as you have discovered on your form these aren't reflected until you click in that fields bound control.

Filter combobox dropdown options using textbox value in Access 2013

I have a form in Access with a textbox and a combobox, and need to filter the combobox dropdown options using the value in the textbox. The textbox contains a Category for the choices.
I've done this using
SELECT Options.Choice
FROM Options
WHERE (((Options.Category)=[forms]![FormName]![Text10].Value));
Is there a way to refer to the value in Text10 without explicitly referring to FormName?
I'll need to duplicate this form within the same Access file and changing all combobox row sources for a new form is not feasible. I can't hard code the Category value for each combobox because there are many comboboxes per form, and the value in the textbox will be different on every form. Any help is appreciated.
You can refer to whatever form you're currently on in Access using Screen.ActiveForm. So in your case you'd have:
SELECT Options.Choice
FROM Options
WHERE (((Options.Category)=[Screen].[ActiveForm]![Text10].Value));
As long as the field name stays constant this should work.

How to bind a textbox to linked child field of subform in MS Access?

So I've got form which has a subform which binds to some textbox on the form. Now within the subform how can I get access to the value in the "child field"?
Here is a good manual about referencing.
Okay, I found a solution to my problem: the textbox on the form was some content of the currently selected row of a table. Now I added an event to this form for changes of the row-selection (Form_Current) which calls a method which manually sets the textbox value directly via a column of the selected table-row like this:
[Forms]![MainForm]![SubForm].[Form]![SubSubForm].[Form].SomeTextBox.SetFocus
[Forms]![MainForm]![SubForm].[Form]![SubSubForm].[Form].SomeTextBox = [Forms]![MainForm]![SubForm].[Form]![SubSubForm].[Form]![SubSubFormTable].[Form]![NeededColumn]
When you link the subform inside Form the filter will work automatically just add the field belong to the child field(ChiledTable). if this not what you mean provide sample of DB.

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