Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003

    Unanswered: How to open a Report and a Form in one Private Sub

    Dear All

    Here is a code I am using in one of my forms.

    The way it works is that there are two reports and one form to view when an option is selected in an option group. On OnClick event of a report command button I have put the following code and it works fine.

    Private Sub CmdReportView1_Click()
    Call viewresults("R_ReportView")
    End Sub

    Private Sub viewresults(rptPrint As String)
    If IsNull(Forms![New form Sample]!CbCustomer) Then
    MsgBox "Please select a customer to proceed!", vbInformation, "Operator Error!"
    Exit Sub
    End If

    Dim stWhere As String
    Dim myInt As String
    Dim myInd As String
    myInd = CbCustomer

    Select Case Me!frmRelativequeries1
    Case 1
    myInt = Forms![New form Sample]!Cbpartno
    stWhere = "[CUSTOMER] = '" & myInd & "' And [PART NO] = '" & myInt & "'"
    Case 2
    myInt = Forms![New form Sample]!Cbrejcode
    stWhere = "[CUSTOMER] = '" & myInd & "' And [REJ CODE] = '" & myInt & "'"
    Case 3
    myInt = Forms![New form Sample]!Cbliabcat
    stWhere = "[CUSTOMER] = '" & myInd & "' And [CAT] = '" & myInt & "'"
    Case 4
    myInt = Forms![New form Sample]!Cbcustomerdefcode
    stWhere = "[CUSTOMER] = '" & myInd & "' And [DEFECT CODE/COMPLAINT CODE] = '" & myInt & "'"
    Case Else
    stWhere = ""
    End Select
    DoCmd.OpenReport (rptPrint), acViewPreview, , stWhere

    The question is how and where I can insert following DoCmd statement to open a form?

    DoCmd.OpenForm (rptPrint), acNormal, , stWhere

    At the moment what I have done is that I have created another similar Private Sub. And Onclick event of Form command button calls for this Private Sub. What I want is if I can do the job within one sub procedure.


  2. #2
    Join Date
    Oct 2003
    if you want the form to end up on top/in front of the report, put the docmd.openform statement after the openreport line; otherwise, put it before.

Posting Permissions

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