MS Access: text box value show #Name? - sql

I have created a form and set the form's RecordSource to a query. Below is my query:
SELECT GeneralT.*, SalaryT.[Status]
FROM GeneralT INNER JOIN SalaryT ON GeneralT.Deposits = SalaryT.Deposits;
In the form I have 4 textboxes. In the first 3 textboxes I show value from GeneralT table and in fourth textbox I show SalaryT.[Status] value. But this fourth value doesn't show in the textbox rather it show #Name?.
If I open the query in datasheet view I can see all the value properly. I don't understand what is wrong here. Please help me to show the result properly in the form.

Displaying #Name? for a field says that field has a control source that does not match with the query linked to the form. Some things to check:
Make sure Status is a selection from one of the pre-existing options in the Control Source drop down combo box. Click on the combo box to make sure.
Double check to make sure it is a "Text Box" and not a custom
control.
Make sure there isn't another text box named Status

Try chaning the control source to just Status instead of SalaryT.[Status]. If the field name does not conflict with the naming of a field in GeneralT, the selected SalaryT.[Status] will actually be displayed named Status.

Related

My query, getting value from a textbox inside a subform, shows "small box"

The overall scenario: Actually trying to implement an order entry
system. A button on the main form opens 2nd form. In the 2nd form,
there are some combo-boxes and list-boxes from which the user selects
an item. Then pressing a button add that item with append query.
The problem is, as soon as I click anywhere in the 2nd (child) form;
the the id (autonumber) from parent vanishes(becomes null) for new
entry in the 2nd form. (I have lately discovered this vanishing by
using a text box to show current parent-id. Also found a solution,
posting as an answer)
I am trying to get two values from a textbox and a combo box. In the query datasheet view, i checked that, one value is received correctly but the other value it shows a very small box (putting picture below)
)
In this picture, "Expr2" field is showing small box. I used below statement to pull value from subform:
Expr2:[Forms]![customer_f]![products_add_subf].[Form]![customer_id]
And here is the code in sql-view:
INSERT INTO products_t ( product_name, customer_id )
SELECT [Forms]![customer_f]![products_add_subf].[Form]![item_combo] AS Expr1, [Forms]![customer_f]![products_add_subf].[Form]![customer_id] AS Expr2;
What this small box mean and how to avoid it ? How to pull correct value instead of small box ?
The solution will prevent vanishing of parent-id from first form(parent); in the 2nd form (child).
Just disable "Allow Addition" in the 2nd form's property.
Steps:
Open the 2nd form in "design view" . Double Click at the upper left corner of the form to open its property sheet. Goto "data" tab. In the "Allow Addition" select "no".
Now your append query will be able to grab the parent id field. It will not vanish !

MS Access - FIlter subform based off listbx

I am trying to filter a subform based off a value selected in a listbox.
My list box is called cboCurrentListName and this is populated using a select query
The subform is called Form_subform_ListContents
For the change event for the list box I have the following code, however no filters are applied when its executed.
Me.Form_subform_ListContents.Form.Filter = "[ListName]=" & Me.cboCurrentListName.Value
Me.Form_subform_ListContents.Form.Filter = True
I have also tried using Master/Child links to execute this using the following steps, but this caused an input box to pop up when the fom loaded:
first I set the 'link child fields' option in the properties of the subform to 'ListName' (this is the field name that populates the list box and is present in the subform
then I set the 'link master fields' option in the properties of the subform to 'cboCurrentListName' (the listbox name)
then in the listbox properties I set the control source to 'cboCurrentListName'
The above steps cased an input box to pop up on opening the form (the value typed in here does filter the subform). However I don't want an input box in order to do this, I want to use the listbox.
I have googled this and fried different methods but have had no luck. I am pretty new to access and of the control source sections aren't a strong point of mine, which is why I tried to use the VBA on the event change instead
Any help would be appricaited, I tried a few things and had no luck.
EDIT: When trying the master/hild option I also get an error 'Can'y build a link between unbound forms' if I click the 3 dots in the poperties. SO for the above steps I had to manually type in the otpions.

Getting a Value if a Field and Record number is known?

Good Evening,
I am working on a Combo Search Form that is designed to search for information by criteria. The form has a combo box containing field values and a text box beside it. The selection of a field value in the combo box will fill in the text box beside it with the relevant information for that record, all the relevant information is contained in the PetTable.
I have managed to get the combo box to display the fields from the PetTable by setting the rowSource to PetTable and the sourceType to Field List... however that's where I hit my dead end.
In the Text Box beside the combo-box I tried grabbing the value of the combo box and putting it into the textbox by making the Text box control source "=ComboBox", however this just created a textbox which has a literal text string to that of the combo box.
My next thought was to make the text box Control source "=PetTable.PetComboBox" my thought was that the PetTable references the table with my information and the "PetComboBox" becomes the field a need to get. This did not work either and gave a #Name error"
What should be happening is: In the Combo-box if I selected [Pet Name], I would hope that the textbox beside it becomes "Fido" but instead it also becomes [Pet Name].
Any and all help would be appreciated!
Thanks
Desired Effect
What you need to do is to change the Row Source Type of the Combo Box to "Table/Query". Then in the "Row Source" click on the "..." to open up the Query Builder. Select the table that you want. Add the columns that you want. I would suggest the table's primary key PetID, and then any other fields - in your case at least PetName. You may also want to sort by PetName to make it easier for the user to scroll through. Close the Query Builder and save the changes. Change the combo box's ColumnCount to 2, and set the Column Widths to be "0cm;6cm" (setting the first column to have a width of 0 means that it is not displayed to the user).
Now move to you TextBox, and set the Control Source to be:
=[Combo0].Column(1)
Note that columns in a combox box are 0-indexed, so the first column is column 0, the second (in your case containing PetName) is column 1.
As you actually want to show the field names, rather than the data in the combo box, then you will need to set the RowSourceType to be "Field List", and then select the table name as the RowSource.
You will then need a small piece of VBA to lookup the value of that field in the table for the current record:
Sub sListFieldData()
If Not IsNull(Me!Combo0) Then
Me!Text2 = DLookup(Me!Combo0, "tblPet", "PetID=" & Me!PetID)
Else
Me!Text2 = ""
End If
End Sub
And you will then need to call this procedure in the combo box's AfterUpdate event (to catch when it has been changed by the user) and also in the form's Current event (to catch when the user moves between records):
Private Sub Combo0_AfterUpdate()
Call sListFieldData
End Sub
Private Sub Form_Current()
Call sListFieldData
End Sub
Regards,

Add a field value to text box

I have an Access Table named Count. It has one field named Anz and it has only 1 record. I want to Show this record in a TextBox on a form named overview. So in the design mode of the form inside the TextBox I use the code
[Count]![Anz]
but it Returns me #Name? error when I Switch back to form mode. Where am I going wrong?
You can use in Control Source of your unbound text box =Dlookup("[Anz]","[Count]")
Also you can bound your form to Count table and use for text box control source Anz

Microsoft Access 07 VBA: Using Text Box or Combo Box as a Control to hide Columns

I currently have a form. The form contains a subform that displays a Query. The Form also has 2 Text Boxes and buttons for both Boxes. The first box acts as a filter for the query to filter specific record. The second box is intended to be used to hide columns in the query. My issue is that my code will not recognize the text box, or any outside source from my form as a Field Name to be found. Here is my current code:
Private Sub Command137_Click()
Forms![Vermont]![Query1 subform].Form.[Query1 Field Name].ColumnHidden = True
End Sub
Currently if I replace "Query1 Field Name" with any field name that exists in the query the column will hide. However if replaced with anything else I recieve the following error:
"Runtime Error '2465'
Microsoft Access Can't Find the Field '|' reffered to in your expression"
I am pretty sure that I am not referencing the Form Control correctly. I have tried replacing [Query1 Field Name] with the following:
[Text142.Text]
[=Text142]
[Text142]
[Forms![Vermont]![Text142]]
I am very new to VBA but I definitely feel as if this is an easy fix; if possible.
Thank you in advance for any help!
Subform references are always a bit weird. This should work, though:
Forms![Vermont]![Query1 subform]![Text142].ColumnHidden = True