Passing Query Expression through Naviagtion Form - vba

I have been practicing the use of building expressions through query design. I have created a custom search query using textfield's and a listbox from a form. Now if I run the query through the form it works. But when I run the query through the form after its been placed within navigation form it does not work. I receive the pop up window to input parameter values manually. I am trying to adjust the expression but cant seem to get the syntax correct.
Below is amended expression but still does not work
[Forms]![Navigation Form Main]![Reports Form]![customerListBox]
For clarification the report form is a tab within my navigation form and yes the expression is being called only when the reports form tab is selected.

Instead of [Reports Form], try [NavigationSubform] which is default name of container holding [Reports Form].

Related

How to requery a form from navigation form?

I've struggling with this problem on my own, then with some help, then search about it; but I haven't had any luck. So I decided to ask
I have two forms in access 2007.
1. frmNavigation
2. frmOrderList
The form frmOrderList is embedded in the form frmNavigation. The form frmOrderList is built based on the queris which have criterias located on the form frmOrderList.
When the criterias are change the macro (after update) start run and trying to refresh the the frmOrderList.
I tried to serveral codes but it dosen't wortk for me.
Forms![frmNavigation]![NavigationSubform].Form![frmOrderList].Requery
Forms![frmNavigation].Form![frmOrderList].Requery
Forms![frmNavigation]![frmOrderList].Form.Requery
Forms![frmOrderList].Requery ' Works fine for the single form
Still the same error
Microsoft access can't find the field 'frmOredrList' referred to in your expression
It is good cheatsheet in russian - http://www.sql.ru/faq/faq_topic.aspx?fid=156 I'd like to translate some points:
Basic syntax is this:
Forms![Form1].Controls![Field1].Value
Mention, that "." and "!" goes one by one, switches.
It is possible to do like this:
Forms![Form1]![Field1]
But there should not be same named different collections' objects.
Addressing subform
Correct link to the property of subform or subreport needs to address full form identifire, using Form property of control:
Forms![Form1].Controls![Form2].Form.Controls![Field1].Value
In this case:
Forms![Form1].Controls![Form2] is a link to a control, where subform is displayed.
Forms![Form1].Controls![Form2].Form - is a link to subform. Addressing Form property is required for MS Access 97, and optional for next versions.
As described, addressing to 3rd and more level subforms is constructed:
.Controls![Form2].Form (or .Controls("Form2").Form )
For addressing to an object in current context
It is recommended to use following syntax:
Me.Controls![Field1].Value
NB: name of control, that contains form can be different from form's name. It can be checked through studying .Name property of a control.
So using these instructions, your code should be following (see 2nd recommendation):
Forms![Form1].Controls![Form2].Form.Controls![Field1].Value
in this case
Forms![frmNavigation].Controls![NavigationSubform].Form.Controls![frmOrderList].Form.Requery
And this will work, only if only names of your controls are same as Form's names, otherwise you should correct names of control names, that are in squre brackets.

QTP - Clicking on a button with a given value

I've started using QTP last weekend so I'm still a bit confused about some things.
I've coded a function that opens an URL on IE, performs some actions and writes a report. But I have a little problem: at a certain point the function has to click on a button to go on but this button's value is changed at every refresh of the page.
For example: at the first access the button's value (or label) is "Results List (51)" but, if I refresh the page, the value becomes "Results List (11)".
What changes is the number inside the brackets (that identifies the number of results inside the list).
Obviously I recorded the action only one time and the result is this:
Browser("myBrowser").Page("myPage").Frame("myFrame").WebButton("Results List 51)").Click
How can I click on the button without having to worry about it's value?
You should open the object repository and have a look at the description that was create for your WebButton then make the property in question a regular expression.
In your case the value should be Results List \(\d+\), this means Result List followed by open-parentheses, followd by one or more digits (a number) followed by close-parentheses.
Here's an explanation on how to use regular expressions in UFT.
This question reminded me of the days when I was a beginner in QTP ;) I think I still am!
Coming to your question -
If you don't really care about what is inside the brackets then you can just give Results List*.* but if you want to check if there is a bracket and digits within it then use the value suggested by Motti i.e. Results List (\d+)
Detailed Steps as you are a rookie:
1) Go to Resources->Object Repository
OR
In the Resources pane expand your action and double-Click the local object repository (You recorded hence the objects will be in local)
2) Click on the Concerned Object so that the object properties specific to this object is displayed.
3) Select the property (name?), at the extreme right you will see a button to configure the value, click on it.
4) Type the text Results List (\d+) or Results List*.*, select the checkbox for regular expressions.
5) A message box will appear, Click on No and then OK button.
Your script should run now!

If statement in MS Access Expression Builder on Control Source

I have an unbound textbox on my form I put on the control source =Date()-[boundfield] and it works fine it gives the number of days I needed but I wanted to have an If statement in this unbound field so using the expression builder I typed on the Control Source.
=iff(Date()-[boundfield] > 120, "Max","not max")
But the unbound field always display #Name?.
What might be the error on my code?.
=IIf((Date()-[Adate])>120,"P","N")
This should work, put brackets as like this

Microsoft Access 2013 Form Objects

I have a database that was create in Access 2010. We recently updated our systems to Access 2013. In Access 2010 I have no errors accessing a form object with
Form_frmName.txtFieldName.Value
However, when using Access 2013 I get a runtime 2424 error stating that "The expression you entered has a field, control, or property name that Microsoft Access can't find. I am accessing from a module.
The module sets these fields visible using
With Form_frmName
.txtFieldName.Visible = True
End With
before attempting to access them.
Has there been any changes in the way form objects are accessed between 2010 and 2013? Is this an issue others have faced?
In Response to #WayneGDunn's questions below
QUOTE:
I need to know exactly what and how you are using this.
1. You have a bound textbox named 'txtFieldName' on a form. As #brad asked, is there a subform, and if so, is this field on the subform?
2. You said the code is in a module, but is the code in the form where the field is defined?
3. Please explain where/what form 'frmQAtab' is (you said your form name was 'frmName', so what is the other, how related?)
4. Is the code in an event? Can you share the entire subroutine?
5. Have you tried creating a dummy query and using the builder to reference the field?
RESPONSE:
1. I have a form (frmMain) with multiple tabbed pages. frmName is one of those tabs, containing the bound field txtFieldName.
2. The module is run from the form the field is in.
3. My apologies frmQAtab is frmName, I just neglected to make that generic in my copy-paste.
4. The event is a button click. The button click runs a sub from a module. That sub makes visible the fields, runs a query based on user input (two date fields), populates the bound fields with the returned record set, then attempts to access them for processing (another query is run to process a complete other set of fields). To post the entire subroutine would be a bit more than I would ask you to chew on. This is legacy code I'm trying to fix, and it's rather large.
5. I have not tried a dummy query. Access is not my field (I'm mainly a C#, scripting, guy.) Is there some suggestions in this area you could give?
One of the following references to your fields should work. I created a form (named 'frmMain'), then created a Tab Control with two tabs. On the first tab, I inserted another form (named 'frm3197'). I also created a text box on the tab control named 'txtFieldName' AND in form 'frm3197'. From a button click on 'frmMain', the following will reference each of those fields.
Private Sub cmdButton1_Click()
Forms![frmMain]![txtFieldName] = Now()
Forms![frmMain]![frm3197].Form![txtFieldName] = Now()
End Sub

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.