title: runtime error 2448 you cant assign a value to this object
body: <p>I am using <a href="https://stackoverflow.com/questions/2660704/ms-access-print-report-using-vba">David-W-Fenton's answer to this question </a>to try to allow users to print a report when they click on a control, but I am getting the following error message:  </p>
  
  <pre><code>runtime error 2448: you cannot assign a value to this object.
  </code></pre>
  
  <p>The line of code triggering the error is:  </p>
  
  <pre><code>Me.txtPageTo.Value = numPages  
  </code></pre>
  
  <p>Here is the full code of the OnLoad event handler for the form:  </p>
  
  <pre><code>Private Sub Form_Load()
      Dim varPrinter As Printer
      Dim strRowsource As String
      Dim strReport As String
  
      If Len(Me.OpenArgs) &gt; 0 Then
          strReport = Me.OpenArgs
          Me.Tag = strReport
          For Each varPrinter In Application.Printers
              strRowsource = strRowsource &amp; "; " &amp; varPrinter.DeviceName
          Next varPrinter
          Me!cmbPrinter.RowSource = Mid(strRowsource, 3)
          ' first check to see that the report is still open
          If (1 = SysCmd(acSysCmdGetObjectState, acReport, strReport)) Then
              With Reports(strReport).Printer
                  Me!cmbPrinter = .DeviceName
                  Me!optLayout = .Orientation
              End With
              Dim numPages As String
              numPages = Reports(strReport).Pages
              Debug.Print "numPages = " &amp; numPages
              TypeName(Me.txtPageTo) 'added this line as a test after
              Me.txtPageTo.Value = numPages
          End If
      End If
  End Sub
  </code></pre>
  
  <p>numPages prints out to equal 0 just before the error is thrown, even though the report should have at least one page.  Also, the error does not get thrown when the form is already open.  The error only gets thrown when the form has to be opened. (Probably because the offending code is in the onload event.)  </p>
  
  <p>When I added TypeName(Me.txtPageTo) , it triggered runtime error 2424: The expression you entered has a field, control, or property name that <em>mydatabasename</em> cant find.  </p>
  
  <p>I think the problem is that I need to set the control source for txtPageFrom and txtPageTo.  But how do I do that?  This form will only be loaded by a vba method that is trying to print a report, so the values for txtPageFrom and txtPageTo will come from the calling method, not from some underlying data table.  (there is no underlying data table for this dialog form.)    </p>
  
  <p>cmbPrinter and optLayout seem to be populating correctly using the code above.  </p>
  
  <p>Can anyone show me how to get past the error messages so that the form loads properly?  </p>
  
  <hr>
  
  <p><strong><em>CORRECT, COMPLETE ANSWER:</em></strong>  </p>
  
  <hr>
  
  <p>The answer to this problem was to greatly simplify the code.  The code in the link at the top of this posting is WAY TOO COMPLEX, and tries to reinvent things that are already done well by the tools built into Access and VBA.  I was able to print reports without any of the complicated solutions by simply using the following code in the on-click event of a control on a form associated with the report:  </p>
  
  <pre><code>Private Sub txtPrintReport_Click()
      On Error GoTo Error_Handler
      Dim commNum As Long
      commNum = Me.CommunicationNumber
      Dim strReport As String
      Dim strVarName As String
      strReport = "rptCommunicationFormForPrinting"
      strVarName = "CommunicationNumber"
      DoCmd.OpenReport strReport, acViewPreview, , strVarName &amp; " = " &amp; commNum, acWindowNormal, acHidden
      DoCmd.RunCommand acCmdPrint
      DoCmd.Close acReport, strReport
  Exit_Point:
  Exit Sub
  Error_Handler:  'this handles the case where user clicks cancel button
      If Err.Number &lt;&gt; 2501 Then
          MsgBox Err.Description, _
          vbExclamation, "Error " &amp; Err.Number
      End If
      DoCmd.Close acReport, strReport
  End Sub  
  </code></pre>
  
  <p>That is all the code that was required.  Much less than the link at the start of this question.  And also much less than the answer below.  I am marking John Bingham's answer as the accepted answer because he clearly worked a lot on this, and I am very grateful for that.  But I ended up solving the problem with A LOT LESS CODE.  My solution does not require the custom dialog form because it uses the Windows print dialog form.  As such, the on load event code in my posting (taken from the link above), is not necessary.</p>