First, you assign "MAIN CLIENT INFO2" to strDocName, but then don't use
strDocName. But you use MAIN CLIENT INFO (without quotes) in your OpenReport
command. So you should either use strDocName or put some quotes around MAIN
CLIENT INFO. (strDocName is not declared in your code snipped, but I assume
it's declared in your actual code.)
Second, regarding the subform, since your subform control has a space in the
name, you need to surround the name in brackets, so Access knows it's all
one name, as in [CLIENT CONTACT].
Third, you need to refer to the subform, itself, to access a field in that
form. Currently, you're just referring to the subform control. Thus, instead
of Forms![CLIENT CONTACT]!ID, you need to use Forms![CLIENT
CONTACT].Form!ID. (This assumes that the subform control name ("Name"
property of the subform control) is the same as the subform name ("Source
Object" property of the subform control.)
Fourth, you should get the ID value and concatenate it to the "ID=" part of
the string, as in:
strFilter = "ID = " & Forms![CLIENT CONTACT].Form! ID
Thus, your entire code (assuming you use strDocName) should look like this:
Dim strFilter As String
Dim strDocName as String
strDocName = "MAIN CLIENT INFO2"
strFilter = "ID = " & Forms![CLIENT CONTACT].Form! ID
DoCmd.OpenReport strDocName, acViewNormal,, strFilter
HTH,
Neil
"Randy" <ra****@msn.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I have tried the code to attach a button to a form and use the help
information on coding, but I can't seem to get it to work.
I have a main form called MAIN CLIENT INFO2
There is a subform called Client Contacts.
I want to print the current record using the ID field in the Client
Contacts subform in a report.
I want to print to a report called MAIN CLIENT INFO using the current
record in the subform.
When I use:
Dim strDocName As String
Dim strFilter As String
strDocName = "MAIN CLIENT INFO2"
strFilter = "ID = Forms!CLIENT CONTACT! ID"
DoCmd.OpenReport MAIN CLIENT INFO, acViewNormal,, strFilter
It does not work.
Appreciate any help as I am new to this Access.