How to set value in the textblock based on other textboxes and query in Access? - sql

Right now I have such form:
The aim, that I'm trying to reach, is to open another form based on block_id value by pressing button. And it works. But block_id value in textblock should be based on three other values in the form: N_table, target_table and source_table. In the attached picture can be seen block_id's textblock form options. Source values for that textblock is query with name s2, and I tried to limit block_id value by setting filter here this way:
([s2].[N_table]=[Form1].[Список0]) AND
([s2].[target_table]=[Form1].[Список2]) AND
([s2].[source_table]=[Form1].[Список4])
There s2 is the query name, Form1 is the name of current form, Список0 and so on is the just list of values for first 3 textboxes. However that doesn't work at all. So block_id is independent. That is wrong here and how it can be fixed?
PS I'm really sorry for not english language in the attached picture, I can't change the language. And I tried to deal with the problem by using Event Processing macros but failed.

I can't read your language, but it looks if the FilterOnLoad property is set to No. Change it to yes, then it should work.

Related

How do I to filter a subform in Access? What is the control name?

I am trying to filter a table with a form and I'm having trouble with the macro.
My form is similar to this one and field1 is first name, field2 is city, and field3 is birth year.
I want to run this query on the subform or something similar so it filters the subform based on the combo box parameters.
My issue is with the control name I can't seem to come up with anything that works.
Thank You! Any help will be appreciated!
Did some testing. The Control Name is the name of the subform container control. In this case it will be the container name only, no Forms!Form1 prefix. Recommend you name the container control different from the object it holds, such as ctrDetails. It works if the container holds a table, query, form, or report.
New here - so couldn't comment or vote on answer above. Using the name of the container worked for me! The container is essentially the yellow subform border when you highlight the subform. The container name is found in property sheet > other > name. And it was searchable in the Control Name box when building the macro.
Property Sheet:
Macro:

MS Access: text box value show #Name?

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.

Gray out a form row's (detail's) button conditionally with VBA code

I have a standard form in MS-Access which lists a bunch of orders, and each row contains order no, customer, etc fields + a button to view notes and attached document files.
On request from our customer we should gray out the button btnAnm (or check or uncheck a checkbox) depending on a calculation from two queries to two other tables (a SELECT COUNT WHERE and a check if a text field is empty).
I've tried btnAnm_BeforeUpdate(...) and btnAnm_BeforeRender(...) and put breakpoints in the subs, but none of them trigger. The same if I use the control Ordernr instead of btnAnm.
I'd like a function in the Detail VBA code to be triggered for each "Me." (row) so to speak, and set the row's control's properties in that sub.
What do I do? I've looked at the help file and searched here.
*Edit: So I want to do something that "isn't made to work that way"? Ie. events are not triggered in Details.
As an alternative, could I base the value of a checkbox on each line on a query based on the 'Ordernr' field of the current row and the result of a SELECT COUNT from another table and empty field check?
Do I do this in the query the list is based on, or can I bind the extra checkbox field to a query?
A description of how to do this (combine a COUNT and a WHERE "not empty" to yes/no checkbox value) would be perfectly acceptable, I think! :)*
You cannot do much with an unbound control in a continuous form, anything you do will only apply to the current record. You can use a bound control with a click event so that it acts like a button.
Presumably the related documents have a reference to the order number that appears on your form, which means that you can create a control, let us call it CountOrders, with a ControlSource like so:
=DCount("OrderID","QueryName","OrderID=" & [OrderID])
The control can be hidden, or you can set it up to return true or False for use with a textbox, you can also use it for Conditional Formatting, but sadly, not for command buttons.
Expression Is [CountOrders]>0
You can also hide the contents and add a click event so that is acts in place of the command button. Conditional Formatting will allow you to enable or disable a textbox.
As I understand your question, you have a continuous form with as command button that appears on each row - and you'd like to enable/disable the button conditionally depending on the contents of the row.
Unfortunately you can't do that. It seems that you can't reference the individual command buttons separately.
Having wanted to do something similar in the past I came up with two alternate ways of setting up my interface.
Put a trap into the onClick code for the Button. Which is icky, because it is counter intuitive to the user. But it gets you that functionality now.
Move the command button (and editable fields) up into the form header, and make the rows read only. Your users then interact with the record only in the header, and select the record they want work with in the list below. As I recall this is known a Master-Detail interface.

Can a combobox present more then one column on its textbox part?

I have a two column list in my combobox and when I choose one of the items in it using the drop down list, it stores (what I see in the textbox part of the combobox) only the value I selected (wether it's the one on the right or left column according to boundcolumn)
My question is: Is there a way to store(or present-that is my goal) in the textbox part of the combobox, both of the columns of one row selected?
For example: [column1] Daniel [column2] Smith. And in the textbox I want: Daniel Smith (and not just Daniel, or Smith on they're own)
What you describe is theoretically possible, but with restrictions.
Even when you didn't ask for that, here comes my idea:
Like described here you can change your ComboBox's text without changing its value. This allows you to 'store' the underlying value while displaying both columns in one.
Listen on the SelectedIndexChanged Event and change the text property as follows:
Sub ComboBox1_SelectedIndexChanged()
ComboBox1.Text = ComboBox1.Column(0) & "-" & ComboBox1.Column(1)
End Sub
(This is only a basic example.) Can't test it right now, but in .Net you can use CType to explicitly convert the sender argument to a ComboBox variable and access it this way.
The Boundcolumn property can't be changed to multiple values. You can try to use VbTab as a delimiter in the text field but i'm not sure how it will appear.
Edit:
Don't forget the default values. I think your Text field should show both columns before the user clicked on the list the first time, too.
You can set a combobox text field to use data from multiple columns but you may need to write some code to do it.
Try http://www.contextures.com/Excel-VBA-ComboBox-Lists.html

Populate list box from a table in vba

I am developing a vba form for employee database, in that there is a search criteria for userid and employees name with the userid should be displayed in a list box control which comes from a single table
I need to populate a list box with value from a table according to a value in a text box which act as a search box (eg: userid)
Please help me how to do this
You question is hard to answer because it depends on some things like data types of the search field etc. So this answer is going to be vague on some of those points...
First off you need to create your listbox with search criteria that will look on the form for the search value and filter accordingly.
You do this by setting the the RowSource property of the listbox. HEre is an example rowsource for a a listbox that looks for a textbox on a form for its filter value...
SELECT tblAgencies.AgencyID, tblAgencies.OrganizationName
FROM tblAgencies
WHERE (((tblAgencies.OrganizationName)
Like "*" & nz([Forms]![frmMainMenu2]![txtSearchAgencies],"") & "*"))
ORDER BY tblAgencies.OrganizationName;
The key part is the Like... line. A couple of things about it...notice that the query looks to the form for some criteria. You see that in the [Forms]![frmMainMenu2]![txtSearchAgencies] part of the query. So there is a search textbox on frmMainMenu2 that is called txtSearchAgencies.
Notice also that I am using NZ function to ensure that the peek onto that textbox returns at least an empty string. Finally notice that is uses the Like operator with wild cards at both ends so that the user can type a partial string.
Finally...next to your search box put a command button to execute the filter/search. All that it has to do is REQUERY the listbox like this...
Me.lstAgencies.Requery.
You could also try to Requery at the OnChange event which would filter as they type. But if your query is slow this may not work well.
Seth
Let's say you have a table TABLE1 that has fields userid, employee.
You should create a form that has a combobox(named boxid) and textbox(named EdtEmployee).
Define a rowsource value of combobox like
SELECT table1.userid FROM table1 WHERE employee like EdtEmployee & "*";
Then define a lostfocus event of a textbox like this
Private Sub EdtEmployee_LostFocus()
BoxId.Requery
End Sub
I hope, this works for you
I agree with mik.
I just would use an AfterUpdate event instead of the LostFocus which I've neber used.