The following simple function returns the value contained within a particular named control on a given named form:
- Public Function FormFieldValue(ByVal FormName As String, ByVal FieldName As String)
-
FormFieldValue = Forms(FormName).Controls(FieldName)
-
End Function
You could use it by supplying the name of the form containing the textboxes you are looking up, and the fieldname as contained in your table. Note that the fieldname is a text string without the square bracket delimiters, as in "Your Field Name" and not "[Your Field Name]".
Example from VBE immediate window on a live form:
- ? formfieldvalue("frmNotes", "Heading")
-
Finance
You can of course supply appropriate variable names or recordset fields as arguments in place of the fixed values shown above, like this:
- YourValue = formfieldvalue(yourformname, RS!tablefield)
-Stewart