Microsoft Access 2013 Form Objects - vba

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

Related

Can't change value of empty PDF form field from VBA

I'm trying to automate populating a PDF form from MS Access VBA. The form itself is maintained online and so my process is:
Download the form
Open it in Adobe
Auto-populate fields
Save / send it on to others
All of this I'm doing from Access VBA. I've encountered an issue on step 3, however.
What I noticed was, if I try to populate the field from VBA, it works fine if the field already has a value. However, on a new / blank form, it generates an error.
Specifically, I call it using the document Javascript object (jso) thusly:
jso.xfa.resolveNode("form." & jso.getNthFieldName(0)).rawValue = 'test'
If the form field is not populated, VBA errors, saying the object doesn't have the rawValue property.
I'm guessing some sort of model initialization is forestalled until the form is populated at least once. The field reference exists in the jso.xfa model, but the property itself is otherwise inaccessible.
Is there a way around this other than pre-populating a "dummy" form? I'd rather not have to maintain / update it as the original gets changed online.

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.

How to have subforms load after the the main form in access 2010

I have an Access 2010 database, with document information in a primary table.
I have forms that display specific document type information (credit card statements, invoices, etc.) from the table.
I have a main form, with separate subforms, each subform representing a specific document type.
I want to be able to filter from the main form, so that each document type subform displays only the documents that fall within a user-specified dollar amount range.
I'm thinking, that if I can get the sub forms to open after the main form (the reverse of this is the default order), I can set the filter in the open event of each sub form, from the main form, and get my desired results.
What I have found to cause the sub forms to open after the main form, is to remove the SourceObject from the Data tab of the Properties sheet of the sub form; and then assign the sub form name to the SourceObject property in vba in the open event of the main form.
The example I have is Me.MySubForm.Form.SourceObject = "frmSubFormName", where everything on the left is verbatim, and frmSubFormName is the name of my subform.
This isn't getting past the compiler - it's complaining about MySubForm, and unfortunately the post/blog with the example doesn't indicate what "MySubForm" is, in assigning the SourceObject property to my sub form name.
Any thoughts on this approach to the filtering?
Can anyone shed light on the syntax of setting the SourceObject; or perhaps provide another way of having the sub forms load after the main form?
Thanks in advance.
Remove the Form class object reference. Recommend naming the subform container control different from the object it holds, such as ctrSomething
Me.ctrSomething.SourceObject = "frmSubFormName"

MS Access Database form not updating after SQL requery

I have a report that runs from a query. The query does use a global variable but this is not the problem but needed for the explanation. The function for the variable is:
Function Var1() As String
Var1 = strVar1
End Function
The query where statement is:
WHERE (((IIf([MinOfDueDayMin]<0,0,Int([MinOfDueDayMin]/7)+1))<Var1()+1) AND ((tblEquipment.Retired)=False))
which uses the var1 function
The criteria is on a field that is actually a calculation and that is where I think the problem starts.
The report is run for a command on another form using the following code:
strVar1 = InputBox("Enter Number of Weeks for report")
If strVar1 = "" Then Exit Sub
DoCmd.OpenReport "rptEquipPmSchedule", acViewReport
Everything works just fine
On the report I have a double click event that opens a form. This form uses part of the same query. (not the same one but two levels higher) thiS allow the user to change things so i expect to use requery for the report.
If i double click and then not even change anything and then go back to the report I have #ERROR in the fields that have the calculations
i put a me.requery in the activate event of the report. this did not work.
So I tried a work around.
When I double click the report field, i close the report and send the strVar1 value to the form that is opened. then when I close the form I reasign the strVar1 just in case it is lost be an assignment by another user (currently I am the only one using this but did it just to be sure it had the correct value.) Then I open the report again but still get the errors. I did not expect this at all. thought starting the report from scratch would certainly work. I even closed the form just after assigning strVar1.
then in final effort. When I close the form I run the exact same code:
strVar1 = InputBox("Enter Number of Weeks for report")
If strVar1 = "" Then Exit Sub
DoCmd.OpenReport "rptEquipPmSchedule", acViewReport
Which will force the user to input the value for strVal1. Even though this is not what I want but tried this for troubleshooting and I still get #ERROR.
When I run the report for a form that does not have any of the same field, no issues. When I run the report or keep it open with a requery from the form that has the same data, the report will not give the correct results. Note that if I run the query itself, the data in the query is correct.
i also tried using a number instead of Val1() in the query and got the same results.
i also tried the refresh button in the ribbon and get Unknown Function Name and all the data in the report is lost.
Anyone got any ideas??
While your textual explanation is difficult to understand the entire scope, consider re-assessing your workflow. The entire objective is to allow users to run customized criteria for reporting. And your main issue is the strVal does not persist in memory so all references to it fails.
Consider the following points:
Have users set criteria on a dedicated unbound form with button click for report where that report instance is immutable for viewing/printing only and if needed to be changed must be re-run (i.e., button re-clicked).
Access has no need for VBA's InputBox() as strVal can be an unbound textbox on this unbound form whose value remains intact for all open windows.
Have function and all its references point to form field: Form!myFormName!strValuetextbox
Because reports on pretty much any software/web app system is not used as a GUI interface to run actions, users will know if they intend to change report criteria, close current report or go back to entry point and change strVal then re-click button to re-run report.
Keep data entry/input (primary use of forms) separate from data export/output (like reports). From developer and user standpoint this compartmentalization will save you headaches down the road.

VB in Access: Combo Box Values are not visible in form view but are visible through Debug.Print

Code in Form onLoad:
country_combo.RowSourceType = "Value List"
Code in a reset function:
Dim lListIndex As Long
With Me.country_combo
For lListIndex = .ListCount - 1 To 0 Step -1
.RemoveItem (lListIndex)
Next lListIndex<br/>
End With
Code to populate country combo:
*For n = 1 To numCountries*
*countryCombo.AddItem (countryRS.Fields("countryName"))*
*countryRS.MoveNext*
*Next n*
I'm having a problem that occurs AFTER the code to populate the country combobox runs. The values are there as I can run Debug.Print(countryCombo.Value) and it prints out the name of the selected country, but I can't see the values in the combobox at all. They're invisible, and as far as I know there is no visiblity property for specific items, unless I'm completely mistaken.
comboBoxError.png http://img110.imageshack.us/my.php?image=comboboxerror.png
I think you should probably use Access's GUI tools to do what you're looking for. In design mode, click on the field you are trying to populate, then click the "lookup" tab. You can then specify a table to populate the field with and your forms should automaticly update as well.
I've also seen what you describe here - as far as I can tell, it's a bug within Access (I was using 2007) that only occurs when you programatically mess with the contents of a combo box. It does not happen every time. The issue corrects itself if you highlight the text that is in the combo box.
I am experiencing a similar issue with Access 2003. Based on the selection of one combo box, the row source of a listbox is set to an SQL string Basically a SELECT DISTINCT [MyField_Selected] FROM MyTable. For some fields the values are visible in the list box and others it is not. The values are there however as I can access them via code. To make it more interesting it works fine in Access 2007.
Just found the resolution on another forum. Check the format property of the field(s) in question on the table. In my case, when Access 2007 created the table, it put an # format in there. I removed that and all works great!