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
Related
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].
I have an unbound form with some required fields that must be field. I have already executed the vba code to achieve just that. Now my question is how do i specify thefields so that he end user can vividly see those fields. I already have an idea of using red stars but i am open to more suggestions.
You can add (*) symbol in the label that denotes its mandatory to fill.
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.
In my Access database, I have tables with the naming convention of "t_customers" or "t_orders". I have a combo box which lets me pick from these options. For a better look, I want to have the options in the combo box without the "t_", so one of the options is just "customers". Then in VBA, I can access the combo box's value of "customers" and then pass that as a parameter to my function which will export the contents of the associated table "t_customers" to an excel file.
Is this possible to do? I can think of using a select case statement and for each combo box value I manually assign the related table value, but there has to be a better way. Is there some sort of short cut that does this in Access using a relationship or similar feature without coding? Or is there a simpler way to code this?
EDIT:
I am also trying to get the value of the current item selected in my combo box named "cbTable". I have no macros attached to the combo box. I have a button that when pressed it runs a macro which calls my VBA function. In the function I have this code:
Dim cbValue As String
cbValue = cbTable.Value
MsgBox (cbValue)
I get this error:
Runtime Error '424'
Object Required
The error is on the
cbValue = cbTable.Value
line. What is wrong with this code and how do I get the current value of the combo box?
Thanks in advance.
You can set your RowSource for your combobox to
SELECT MSysObjects.Name, Replace(MSysObjects.Name,"t_","") AS Expr1
FROM MSysObjects
WHERE (((MSysObjects.Type)=1) AND ((MSysObjects.Flags)=0));
Then set the Column Count to 2, the Column Widths to 0;2 (the second number just needs to be any positive number) an the Bound Column to 1.
Now when you go to call your function the value of the combobox will be the real name of the table, t-customers, but what you saw on your form was customers.
As for accessing that combobox a few things need to be in place.
Let's say you have a form, Form1, and your combobox, cbTable, is on that form.
So when your form runs it looks like this
Now let's say you have an OnChange even for that combobox
Notice that when you type cbTable it appears in the intellisense (ctrl+space). This tells you that your object is accessible at this scope.
Now if you were in another module where that variable is out of scope you would get this error when you try to compile.
Because Module1 has no idea what cbTable is. However, you can reference anything so long as it's fully qualified. So if we run this test with your form open, and "orders" selected all 3 of these lines are equivalent
Forms("Form1").cbTable
Form_Form1!cbTable
Forms("Form1").Controls("cbTable")
Notice at the top of all my modules it says Option Explicit. This forces your code to basically be checked for syntax/scope validity before you run it. Tools > Options
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