Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.OutputTo and DoCmd.SendObject

Status
Not open for further replies.

Herdrich

Technical User
Dec 30, 2008
83
US
What i have on my Form is three buttons one for report view another for outputto and the final one is sendobject. All of them work when clicked on although i am trying to figure out how i can get the information on my form to filter the sendobject and outputto buttons. This is my code for the report button how do i make this work with the other two?

Code:
Private Sub cmdPreview_Click()
Dim strtype, strwhere, strDateField, strsubtype, strname As String
Const strcJetDate = "\#mm\/dd\/yyyy\#"
strDateField = "[DateDue]"
strname = "[Name]"
strsubtype = "[Type]"

strtype = Me.txtType

    If Not IsNull(Me.txtsubtype) Then
        strwhere = strwhere & " (" & strsubtype & " = " & (Me.txtsubtype) & ") AND "
    End If
    
    If Not IsNull(Me.txtName) Then
        strwhere = strwhere & " (" & strname & " = '" & (Me.txtName) & "') AND "
    End If

    If IsDate(Me.txtStartDate) Then
        strwhere = strwhere & " (" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ") "
    End If
    If IsDate(Me.txtEndDate) Then
        If strwhere <> vbNullString Then
            strwhere = strwhere & " AND "
        End If
        strwhere = strwhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ") "
    End If


DoCmd.OpenReport strtype, acViewPreview, , strwhere
DoCmd.Close acForm, "Report", acSaveNo
 
Got it figured out and this is how.

Code:
Dim strtype, strwhere, strDateField, strsubtype, strname As String
Const strcJetDate = "\#mm\/dd\/yyyy\#"
strDateField = "[DateDue]"
strname = "[Name]"
strsubtype = "[Type]"

strtype = Me.txtType

    If Not IsNull(Me.txtsubtype) Then
        strwhere = strwhere & " (" & strsubtype & " = " & (Me.txtsubtype) & ") AND "
    End If
    
    If Not IsNull(Me.txtName) Then
        strwhere = strwhere & " (" & strname & " = '" & (Me.txtName) & "') AND "
    End If

    If IsDate(Me.txtStartDate) Then
        strwhere = strwhere & " (" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ") "
    End If
    If IsDate(Me.txtEndDate) Then
        If strwhere <> vbNullString Then
            strwhere = strwhere & " AND "
        End If
        strwhere = strwhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ") "
    End If


DoCmd.OpenReport "Appointments Report", acViewPreview, , strwhere, acHidden
DoCmd.OutputTo acOutputReport, "Appointments Report"
DoCmd.Close acReport, "Appointments Report"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top