Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2003
    Location
    Oklahoma
    Posts
    17

    Question Unanswered: Newbie: problem with code

    I am trying to print a report from a form. I want to execute the report command based upon the parameters selected on the form. Here is my code:

    Private Sub btnVisitSheet_Click()

    Dim stReportName, stSendTo, stSheetOptions As String

    Rem MsgBox (fraSendTo)
    Rem MsgBox (fraSheetOptions)
    stSendTo = IIf(fraSendTo = 1, "acPreview", "")

    stReportName = "Visitation Class List"
    DoCmd.OpenReport stReportName, atSendTo


    End Sub
    It keeps giving me type mismatch, although atSendTo equals "acPreview" at this point. Is there something I need to do to atSendTo to pass through "acPreview"?

    Thanks for any help,
    Wayne

  2. #2
    Join Date
    Feb 2005
    Location
    England.
    Posts
    232
    Sorry Wayne, perhaps it's me here, but whats 'atSendTo'?

    You've defined stSendTo, but not that. Perhaps this is the problem?!?

  3. #3
    Join Date
    Dec 2003
    Location
    Oklahoma
    Posts
    17
    Sorry, it should be "stSendTo", which it actually is in the code - I wish the solution were that easy!

    I may as well ask the question, too, as to whether I am even approaching this the right way. Is there an easier way to pass a user's report parameters from the form to the openreport of the button event?

    Wayne

  4. #4
    Join Date
    Feb 2005
    Location
    England.
    Posts
    232
    Should the acPreview be acViewPreview?

    Not sure if this will help, but it could help!

  5. #5
    Join Date
    Dec 2003
    Location
    Oklahoma
    Posts
    17
    That didn't matter when I tried it. It still says "Type Mismatch".

  6. #6
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    try something like this

    Code:
    Private Sub btnVisitSheet_Click()
        Dim stSendto As AcView
        Dim stReportName As String, stSheetOptions As String
    
    
        If fraSendTo = 1 Then
            stSendto = acViewNormal
        Else
            stSendto = acViewPreview
        End If
    
        stReportName = "Visitation Class List"
        DoCmd.OpenReport stReportName, atSendTo
        
    End Sub
    note untested
    acPreview is not a string but an argument hence using a string variable here wont work

  7. #7
    Join Date
    Dec 2003
    Location
    Oklahoma
    Posts
    17
    Thanks, David. That was it. I will research that out and see how I missed it. I really appreciate the help!

    Wayne

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •