Opening Access Forms and Referencing Fields - vba

I'm trying to load a form in Access in order to get field data from it and store that field text into a variable. I want to transfer it to Microsoft Word (but that's another problem for a different day).
This code goes in the Access Object and it's subroutine is referenced in the modules section
DoCmd.OpenForm "ContactDetails"
Dim NameBoxOne As String
NameBoxOne = Forms!ContactDetails!txtFirstName.Value
I receive:
Run Time Error -2146500594 (800f000e) Method 'Item' of object 'Forms' failed when trying to reference a field.
I suspect this is the case because the form hasn't completely loaded after opening, but that is only a guess.

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.

MSAccess VBA: Pass values from a subform to a seperate form

I have a form frmDetail that contains several locked fields I want populated only when another form has been filled out, in the name of having some kind of standardization in my data. This other form frmSignOut is used to enter in a date and location that will populate the fields on frmDetail. frmSignOut also contains a subform subULookup that looks up users from a different table using an identifier number. The resulting last name, first name and phone # should also be passed to frmDetail. I also hope to combine first and last name somehow into a Last,First format.
My approach so far has been to open frmSignOut modally with acDialog and I inserted Visible=False into the On_Click event on frmSignOut. Then I try to reference my subform fields and set them to the desired fields on frmDetail. I finish by refreshing and then closing the dialog form.
Private Sub CmdSignOut_Click()
DoCmd.OpenForm("frmSignOut"),,,,,acDialog
If CurrentProject.AllForms("frmSignOut").isLoaded=True Then
Set Forms!frmSignOut!SubULookup.PhoneNbrTxt=Me.ContactNbrTxt
DoCmd.Close (acForm), ("frmSignOut")
Me.Refresh
End If
End Sub
I have only been able to get this far, trying to pull the first field PhoneNbrTxt. I can get frmSignOut to open, I put in data and when I click my 'close' command button I get run-time error 438: Object doesn't support this property or method.
The line highlighted is where I try to reference my subform field. I also have a 'Cancel' button added to frmSignOut that just closes the form, I have no errors there.
Again I'm completely new to Access without much prior experience in anything related, I'd appreciate any knowledge you guys can throw at me.
EDIT: I've been able to successfully pull the value to Me.ContactNbrTxt by adjusting my code to the below.
Me.ContactNbrTxt = Forms!FrmSignOut!SubULookup.Form!PhoneNbrTxt
It looks like the missing part was the Form! right before the control name, along with formatting this correctly and dropping Set.
Im still trying to work out how to combine first and last name before also pulling those to frmDetail, if anyone can help there.

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"

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

How to Access DataTable Information Filled By a Module From a Form

I have a DataSet named BillMat.xsd
When my application loads, a module fills that dataset's DataTable with the correct information.
My question is ... How can I access that DataTable's already filled information from another form?
Here's how I tried to access it on one of my forms:
Dim View As New DataView
View.Table = BillMat.Tables("dtBillHeader")
But I get the following error:
If I create a new instance of my dataset and store it in a variable, I'll be able to get rid of this error message but it will also get rid of all my data in my dataset's datatables ... Is there a way to access a DataTable's information from another form?
You need to fix it so both forms are referencing the same DataSet or DataTable object. If one is a "child" form of the other, such as a dialog, you can pass it from the parent to the child via a property. Otherwise, ideally, the same data object would be injected into both forms by some third object which created both of the forms. Short of all that, you could create a singleton or global variable, but please don't!